Problem with enity Network Vars

Hello

I’m currently making somes entity, but i have a problem with one of it.
When i increment one network vars, it’s add two and this is not what i want.
I have recorded a small video for showing the problem : https://www.youtube.com/watch?v=YnteQHYySSU&feature=youtu.be

init.lua



--[[---------------------------------------------------------------------------
This is an example of a custom entity.
---------------------------------------------------------------------------]]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")


function ENT:Initialize()
	self:SetModel("models/props_junk/PlasticCrate01a.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)
	self:SetUseType(SIMPLE_USE)
	local phys = self:GetPhysicsObject()
	phys:Wake()
	self.damage = 100

end

function ENT:OnTakeDamage(dmg)


	self.damage = (self.damage or 100) - dmg:GetDamage()
	if self.damage <= 0 then
			self:Remove()
	end
end

function ENT:Use( ply )
	self:Setpasteque(self:Getpasteque() + 1)
end

function ENT:Touch( ent )
	
	if ent:GetClass() == "fruits" then
		if self:Getpasteque() > 10 then

		else
			ent:Remove()
			if SERVER then
					self:Setpasteque(self:Getpasteque() + 1)		
			end

		end
	end

end



function ENT:Think()

	if self:WaterLevel() > 0 then
		self:Destruct()
		self:Remove()
		return
	end

end

function ENT:OnRemove()

end



shared.lua



--[[---------------------------------------------------------------------------
This is an example of a custom entity.
---------------------------------------------------------------------------]]
ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Caisse de fruits"
ENT.Author = "IparazzHD"
ENT.Category = "IparazzDEV"
ENT.Spawnable = true
ENT.AdminSpawnable = true


function ENT:SetupDataTables()
	self:NetworkVar("Float", 1, "pasteque")
	self:NetworkVar("Entity", 0, "owning_ent")
end



what? you’re adding one when you pressing E on it and you’re adding one when the entity is touching it. did you just copy this code from somewhere?

No, it’s my code.
Because i wanted to test it with E for see the result.

Use

ENT:StartTouch instead, the entity is probably calling it twice. Also, all of the Touch hooks are only called server side, so you can get rid of that server check.

Ok thanks, i will try it now :slight_smile:

I have tried but it’s still doesn’t work.

Print out the entity touching it then, see what it prints out. Also just to make sure, you removed the other Touch hook right?

self:NetworkVar(“Float”, 0, “pasteque”)
self:NetworkVar(“Entity”, 1, “owning_ent”)


function ENT:Touch(ent)
	if ent:GetClass() ~= "fruits" or self.hasMerged or ent.hasMerged or self:Getpasteque() > 10 then return end
	ent.hasMerged = true
	ent:Remove()
	self:Setpasteque(self:Getpasteque() + 1)
end

What?

[editline]8th August 2017[/editline]

Ah, that’ll work, though there’s no reason to continue using Touch.

Yeeeeaaaah ! Thanks you it’s work :slight_smile: