• Getting errors but code works?
    5 replies, posted
Hey all. Well ive been making a multi-purpose fists swep, and i cant seem to figure out why the code works, but i still get the error? Is there a way to hide the error? I pasted the code below, maybe(probably) i screwed something up. This is the code for the Door Unlocking/Locking [lua] elseif string.find( trace.Entity:GetClass(), "door" ) then if trace.Entity:GetNWString( "doorowner" ) == self.Owner:Nick() then trace.Entity:Fire( "lock", "", 0 ) trace.Entity:EmitSound( "doors/default_locked.wav" ) elseif trace.Entity.coOwners != nil then if table.HasValue( trace.Entity.coOwners, self.Owner:Nick() ) then trace.Entity:Fire( "lock", "", 0 ) trace.Entity:EmitSound( "doors/default_locked.wav" ) end end [/lua] Error: weapons/hands/shared.lua:229: attempt to call method 'Fire' (a nil value) weapons/hands/shared.lua:158: attempt to call method 'Fire' (a nil value) This is the code for the Picking up items [lua] elseif trace.Entity:GetClass() == "item" then self.Owner:PickupItem(trace.Entity) --Below is the PickupItem function function pmeta:PickupItem(item) self:GiveItem( item.InfoTable.UniqueID, 1 ) item:Remove() end [/lua] Error: weapons/hands/shared.lua:225: attempt to call method 'PickupItem' (a nil value)
[QUOTE=Saint Devil;16950490]Hey all. Well ive been making a multi-purpose fists swep, and i cant seem to figure out why the code works, but i still get the error? Is there a way to hide the error? I pasted the code below, maybe(probably) i screwed something up. This is the code for the Door Unlocking/Locking [lua] elseif string.find( trace.Entity:GetClass(), "door" ) then if trace.Entity:GetNWString( "doorowner" ) == self.Owner:Nick() then trace.Entity:Fire( "lock", "", 0 ) trace.Entity:EmitSound( "doors/default_locked.wav" ) elseif trace.Entity.coOwners != nil then if table.HasValue( trace.Entity.coOwners, self.Owner:Nick() ) then trace.Entity:Fire( "lock", "", 0 ) trace.Entity:EmitSound( "doors/default_locked.wav" ) end end [/lua] Error: weapons/hands/shared.lua:229: attempt to call method 'Fire' (a nil value) weapons/hands/shared.lua:158: attempt to call method 'Fire' (a nil value) This is the code for the Picking up items [lua] elseif trace.Entity:GetClass() == "item" then self.Owner:PickupItem(trace.Entity) --Below is the PickupItem function function pmeta:PickupItem(item) self:GiveItem( item.InfoTable.UniqueID, 1 ) item:Remove() end [/lua] Error: weapons/hands/shared.lua:225: attempt to call method 'PickupItem' (a nil value)[/QUOTE] For your first problem, do you have [code] if( CLIENT ) then return; end [/code] Above it? For your second one, it looks like you're trying to call the PickUp function before it's defined?
Are the errors blue (serverside) or orange (clientside)? My best guess is that you are trying to call serverside functions from the client.
Bingo Robert64, i JUST realized that XD How would i turn them clientside. And the PickUp function is in another file, i just combined them into one LUA box.
He just told you how, put the CLIENT check above it.
I made the same swep exactly quite recently, I had the same problem. :( However it was only in multiplayer.
Sorry, you need to Log In to post a reply to this thread.