I manage a murder server and I’m trying to learn lua to spice things up a bit, but most of the time I just have no idea what I’m doing.
I wanted a simple ~10sec spawn protection, so I took this code and modded it a bit to display when the spawn protection is ON/OFF. However sometimes (I guess when someone joins the server) during a round, the messages “Spawn protection ON/OFF” appear and I don’t really understand why…
Here is the modded code I’m using (Please go ahead and say my code is terrible, including clues as to how I could fix it if possible) :
hook.Add( "PlayerSpawn", "SimpleSpawnProtection.PlayerSpawn", function( ply ) ply:GodEnable() -- Enable god mode on the player. timer.Simple ( 8, function() timer.Create ( "spawnON" , 1, 11, function() PrintMessage( HUD_PRINTCENTER, "Spawn protection ON") end ) end ) timer.Simple( 20, function() -- Starting timer if ( IsValid( ply ) ) then -- We must ensure a player object remained valid after delay (it would be invalid and cause script errors if a player have disconnected from the server).. ply:GodDisable() -- Disable god mode on the player. PrintMessage( HUD_PRINTCENTER, "Spawn protection OFF") end end ) end )
Thank you !