GMOD TTT Problem

Hello
im trying to make a script that gives the player a weapon_zombie

local client = LocalPlayer()

function Zinfect(client)
if (client:IsPlayer() && client:IsValid() &&
client:GetRole() != ROLE_TRAITOR) then
client:StripAll()
client:Give(“weapon_zombie”)
end
end

hook.Add(“TTTBeginRound”, “zinfectply”, Zinfect)

And i get this error:
[ERROR] addons/zombieplague/lua/autorun/client/zinfect.lua:4: attempt to index local ‘client’ (a nil value)

  1. fn - addons/zombieplague/lua/autorun/client/zinfect.lua:4
  2. Call - addons/ulib/lua/ulib/shared/hook.lua:179
    3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:131
    4. func - gamemodes/terrortown/gamemode/cl_init.lua:204
    5. unknown - lua/includes/extensions/net.lua:32

Can anyone help?

You can’t put LocalPlayer() on a serverside script, he doesn’t exist there

Put [noparse]




[/noparse] in your post, it makes it a lot easier to read.
Remove the “local client = LocalPlayer()” from your code, LocalPlayer is never a valid entity on the server.
Also, the TTTBeginRound hook doesn’t pass a player argument, so you’d need to iterate through all the players, like this:



local function DoSomethingToAllPlayers()
    for k, v in next, player.GetAll() do
         -- check if the player is valid
         if IsValid(v) then
              -- do whatever you want here, using v, so something like v:Give("weapon rubbish")
         end
    end
end
hook.Add("TTTBeginRound", "My Hook UID", DoSomethingToAllPlayers)


And have it in lua/autorun/server/