• Simple functions returning nil
    2 replies, posted
I currently have this code: [code] local _R = debug.getregistry().Player; AddRandomPhrase(function(ply) ply:ChatPrint("Wow, you got me"); end) function RandomFunc() for k, v in pairs(RandomPhrases) do return v; end return false; end function ENT:StartTouch(ply) if (ply:IsPlayer()) then self.Entity:Remove() local GotRandFunc = RandomFunc() GotRandFunc:func(ply); end end [/code] Everytime I touch the entity the server console prints out an error similar to this: Error: [code]attempt to call method 'ChatPrint' (a nil value) [/code] No matter what function I try to run on the client, it always returns a nil value. how would i fix this?
[QUOTE=Shenesis;50250071]Try replacing [lua]GotRandFunc:func(ply)[/lua] by [lua]GotRandFunc.func(ply)[/lua][/QUOTE] wow, i feel stupid now. Thanks for the help!
Sorry, you need to Log In to post a reply to this thread.