My code doesn"t work help me x)

Hello, my code doen"t work :


hook.Add( "PlayerInitialSpawn", "moderator", function() 
	if ply:IsUserGroup("operatorpoufsouffle") or ply:IsUserGroup("operatorserdaigle") or ply:IsUserGroup("operatorgryffondor") or ply:IsUserGroup("operatorserpentard") then
		ply:Give("weapon_physgun");
	end
end)

It creates a lua error and I do not understand why ?

Help me !

error :

[ERROR] lua/autorun/server/moderator.lua:4: attempt to index global ‘ply’ (a nil value)

  1. fn - lua/autorun/server/moderator.lua:4
  2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179

On the first line, you need function( ply ), not just function().


hook.Add( "PlayerInitialSpawn", "moderator", function(ply)

You can also simplify it a bit:



local lookup = {
    operatorpoufsouffle = true,
    operatorserdaigle   = true,
    operatorgryffondor  = true,
    operatorserpentard  = true
}

hook.Add( "PlayerInitialSpawn", "moderator", function( ply )
    if ( lookup[ ply:GetUserGroup() ] ) then
        ply:Give("weapon_physgun");
    end
end)

My automerge :frowning:

It’s doesn"t work. Help me pleas

Need more information to be able to help you.

I would give physic to moderator gun from my server without using the trick of setting the darkrp . Thank you

Works for me… are you getting any errors? How are you running this on a server? Do you know the addon is executing? Put print(“Addon has loaded”) at the top and see if it comes out in console.



local lookup = {
    superadmin = true
}

hook.Add( "PlayerInitialSpawn", "moderator", function( ply )
    if ( lookup[ ply:GetUserGroup() ] ) then
        ply:Give("weapon_crossbow");
    end
end)




Semajnad has spawned.
ServerLog: Semajnad (STEAM_0:1:22686651) Spawned
ServerLog: Semajnad (STEAM_0:1:22686651) Attempted to pick up a weapon_crossbow


i test.

also why initial spawn? when they die, they will spawn with default weapons.