Simple lua script

This script doesn’t work


function Plugin:PlayerSpawn( ply )
        if ply:IsUserGroup("superadmin") then
                ply:GodEnable()
                timer.Simple(500, function()
                ply:GodDisable()
                end)
        end
		end

It in the folder: …\garrysmod\lua\autorun\server\

i’m sorry but what are you asking for exactly?

[lua]
hook.Add( “PlayerSpawn”, “adminSpawnGodmode” function( ply )
if ply:IsUserGroup( “superadmin” ) then
ply:GodEnable()
timer.Simple( 500, function()
ply:GodDisable()
end )
end
end )
[/lua]

You wanna hook onto PlayerSpawn, not override it. Unless you’re making a gamemode or something.

i’m sorry,but the script doesn’t work.

Any errors?

  1. You need to check and make sure IsUserGroup returns the correct value
  2. You need to use timer.Create, otherwise timer.Simple may stack multiple times and cause them to lose god when they aren’t supposed to.
  3. You need to check if the player is valid in the timer function.

no

Here, try this;

[lua]
hook.Add( “PlayerSpawn”, “adminSpawnGodmode”, function( ply )
if ply:IsAdmin() then
ply:GodEnable()
timer.Simple( 500, function()
ply:GodDisable()
end )
end
end )
[/lua]

Should probably work better.

Thx everybody. Work