Getting Entity HELP!

hello idk what i need to do here but i have this code and i dont see what i did rong here coz it just seending back an error

[lua] function ENT:Touch(activator)
if (!self.touched) then
local p = self.Entity:GetNetworkedInt( “number”)
local r = activator:GetClass()
if (activator:IsPlayerHolding( )) and (p < self.max) then
local m = activator:GetModel()
if (util.IsValidModel(m)) then
local g = {}
if activator:GetClass() == “spawned_money” then g.class = r else return end
g.model = m
g.tab = activator:GetTable()

– This is The Part I Added (Below)

local en = activator
local total = 0
for k, v in pairs(en) do
if v.GetTable and v:GetTable().moneybag and v:GetTable().dt.amount then
total = total + v:GetTable().dt.amount
elseif v:GetClass() == “spawned_money” and v.dt.amount then
total = total + v.dt.amount
end

table.insert(self.contains, g)
activator:Remove()
p = total
self.Entity:SetNetworkedInt( "number", p )
self.touched = true
timer.Simple(0.3,untouch,self)
else
--play error sound if the model doesn't work, it happens sometimes but this way we don't loose the prop or get an annoying error marker
self.Entity:EmitSound( "common/null.wav", 500, 100 )
end
elseif (p == self.max) then
self.Entity:EmitSound( "common/null.wav", 500, 100 )
end
if (activator:IsPlayer()) then
local a = ents.FindByClass("sent_backpack")
local found = false
local n = nil
for k,v in ipairs(a) do
if (v.player == activator) then
found = true
end
end
if (!found) then  end

end
end
end
function untouch(self)
self.touched = false
end
[/lua]

EDIT: oops sorry the last bit dident past alright so im tring to get the amount of of the spawend_money (DarkRP) but im not to sure how that is what i came up with but it just keeps saying error in the
int file

Error:
darkrp\entities\entities\sent_backpack\init.lua:94: attempt to index global ‘v’ (a nil value)

so if you can fix it or make it so that it grabs the amount off of the activator that would be great thx

:wtc:

What are you even asking us to help with?

It would PROBABLY help if you posted the error in question.

Also indent correctly, please, my eyes burn.

[editline]05:43PM[/editline]

:ninja:

That too

It seems like you’re missing an end after line 22 to terminate the for…in-loop…

[editline]05:53PM[/editline]

If the code worked before adding that piece you isolated, then this is probably the cause of the error.

[editline]05:54PM[/editline]

[lua]function ENT:Touch(activator)

if (!self.touched) then

	local p = self.Entity:GetNetworkedInt( "number")
	local r = activator:GetClass()
	if (activator:IsPlayerHolding( )) and (p &lt; self.max) then

		local m = activator:GetModel()
		if (util.IsValidModel(m)) then
			local g = {}
			if activator:GetClass() == "spawned_money" then g.class = r else return end
			g.model = m
			g.tab = activator:GetTable()

			local en = activator
			local total = 0
			for k, v in pairs(en) do

				if v.GetTable and v:GetTable().moneybag and v:GetTable().dt.amount then

					total = total + v:GetTable().dt.amount

				elseif v:GetClass() == "spawned_money" and v.dt.amount then

					total = total + v.dt.amount

				end

			end -- This end was missing

			table.insert(self.contains, g)
			activator:Remove()
			p = total
			self.Entity:SetNetworkedInt( "number", p )
			self.touched = true
			timer.Simple(0.3,untouch,self)

	else

		--play error sound if the model doesn't work, it happens sometimes but this way we don't loose the prop or get an annoying error marker
		self.Entity:EmitSound( "common/null.wav", 500, 100 )

	end

	elseif (p == self.max) then

		self.Entity:EmitSound( "common/null.wav", 500, 100 )

	end

	if (activator:IsPlayer()) then

		local a = ents.FindByClass("sent_backpack")
		local found = false
		local n = nil
		for k,v in ipairs(a) do

		if (v.player == activator) then

			found = true

		end

	end

	if (!found) then  end

	end

end

end

function untouch(self)

self.touched = false

end
[/lua]

Here’s a properly indented version with the end fixed.

ok now i got this error …

darkrp\entities\entities\sent_backpack\init.lua:95: bad argument #1 to ‘pairs’ (table expected, got Entity)

Well, that’s because the object contained in the variable en is an entity and not a table.

[editline]05:58PM[/editline]

Wait what, this code should work. (:wtc: were you doing with that for loop anyway?)

[lua]function ENT:Touch(activator)

if (!self.touched) then

	local p = self.Entity:GetNetworkedInt( "number")
	local r = activator:GetClass()
	if (activator:IsPlayerHolding( )) and (p &lt; self.max) then

		local m = activator:GetModel()
		if (util.IsValidModel(m)) then
			local g = {}
			if activator:GetClass() == "spawned_money" then g.class = r else return end
			g.model = m
			g.tab = activator:GetTable()

			local en = activator
			local total = 0

			-- Just use en, you don't need any loops here
			if en.GetTable and en:GetTable().moneybag and en:GetTable().dt.amount then

				total = total + en:GetTable().dt.amount

			elseif en:GetClass() == "spawned_money" and en.dt.amount then

				total = total + en.dt.amount

			end

			table.insert(self.contains, g)
			activator:Remove()
			p = total
			self.Entity:SetNetworkedInt( "number", p )
			self.touched = true
			timer.Simple(0.3,untouch,self)

	else

		--play error sound if the model doesn't work, it happens sometimes but this way we don't loose the prop or get an annoying error marker
		self.Entity:EmitSound( "common/null.wav", 500, 100 )

	end

	elseif (p == self.max) then

		self.Entity:EmitSound( "common/null.wav", 500, 100 )

	end

	if (activator:IsPlayer()) then

		local a = ents.FindByClass("sent_backpack")
		local found = false
		local n = nil
		for k,v in ipairs(a) do

		if (v.player == activator) then

			found = true

		end

	end

	if (!found) then  end

	end

end

end

function untouch(self)

self.touched = false

end
[/lua]

lol idk

Well, that’s a very positive attitude to coding.

Indeed. “lol idk i just write some and ask yu”