• Prop Limit
    5 replies, posted
This code doesn't seem to do anything. [LUA] function PlayerJoined(pl) pl.Props = 0 end hook.Add("PlayerInitialSpawn", "PlayerJoin", PlayerJoined) function GM:PlayerSpawnProp(pl) if pl.Props < 16 then pl.Props = pl.Props + 1 else pl:ChatPrint("Prop limit reached.") return false end end [/LUA]
--Snip--
Just use the sbox_maxprops console command. To fix your code, change [lua] function GM:PlayerSpawnProp(pl) if pl.Props < 16 then pl.Props = pl.Props + 1 else pl:ChatPrint("Prop limit reached.") return false end end [/lua] to [lua] hook.Add("PlayerSpawnProp","PropLimiter",function(pl) if pl.Props < 16 then pl.Props = pl.Props + 1 else pl:ChatPrint("Prop limit reached.") return false end end) [/lua]
Your code doesn't work. Also, how is changing the way a function is declared going to fix anything?
I return with my original statement that someone thought was wrong. pl.Props does not exist in the player class, It must be put in by retrieving the metatable and adding it. The way the function is done now pl.props is all relative to the function callback and is garbage collected once the function returns.
Why don't you just use ply:GetCount("props"), instead of creating a new system?
Sorry, you need to Log In to post a reply to this thread.