• Why my SWEP is giving error ?
    7 replies, posted
function SWEP:PrimaryAttack() local stalker = self.Owner if stalker:IsPlayer() then self:DoShootEffect() local otherPlayer = self.Owner:GetEyeTrace().Entity if ( IsValid( otherPlayer ) and otherPlayer:IsPlayer() ) then if not timer.Exists( "nome" ) then if stalker:IsPlayer() and IsValid(stalker) then stalker:addMoney(200) timer.Create( "nome", 5, 1, function() return false end ) end end end end end This is the error: lua/weapons/stalker.lua:51: attempt to call method 'addMoney' (a nil value)   1. unknown - addons/ascps2/lua/weapons/stalker.lua:51
Could be any number of things... stalker.addMoney(200) stalker.AddMoney(200) stalker:AddMoney(200) I'm assuming you're on DarkRP?
Yes.
are you running this code client side or server side?
Server side
actually quick question is the error yellow or blue in the console?
Yellow
Lua errors work like this: Yellow = Client Blue = Server Since it's yellow that means you're trying to set the owner's money on client side but that function doesn't exist on the client's side. Lua Tutorial 3 (If you're to lazy to look at GMod Wiki) You would need to do an if SERVER then statement in the shared.lua file and (I think) you can just copy paste that code into there.
Sorry, you need to Log In to post a reply to this thread.