• Timer is on bahamas?
    3 replies, posted
Hi, I have this code and sometimes the timer just dosent works and players dont get there weapons back. [QUOTE] function GodMode:PlayerSpawn(ply) if !IsValid(ply) then return end ply:GodDisable() ply.GodEnabled = false ply:ChatPrint( "GodeMode enabled for 15 Seconds, after 15 Seconds you can buy weapons and use them." ) ply:StripWeapons() ply:Give("weapon_physgun") ply:Give( "gmod_tool" ) ply:Give("weapon_physcannon") ply:GodEnable() ply.GodEnabled = true timer.Create( "giveback", 15, 1, function() givebacksweap(ply) end ) end function givebacksweap( ply ) if !IsValid(ply) then return end ply:GodDisable() ply.GodEnabled = false ply:Give("weapon_rpg") ply:Give("weapon_pistol") ply:Give("weapon_357") ply:Give("weapon_crowbar") ply:Give("weapon_smg1") ply:Give("weapon_ar2") ply:Give("weapon_shotgun") ply:Give("gmod_camera") ply:Give("weapon_physgun") ply:Give( "gmod_tool" ) ply:Give("weapon_physcannon") ply:ChatPrint( "GodeMode over, you can now use your weapons :)" ) end [/QUOTE] Idea how to fix? Thanks
Don't use timer.Create because if 2 players die within 15 seconds only the most recently added timer will be executed, because if you create timer that has the same identification as another timer, the new timer replaces the older one (and stops the older one). Use timer.Simple instead.
[QUOTE=syl0r;44330669]Don't use timer.Create because if 2 players die within 15 seconds only the most recently added timer will be executed, because if you create timer that has the same identification as another timer, the new timer replaces the older one (and stops the older one). Use timer.Simple instead.[/QUOTE] That will prevent him from stopping the timer if needed. Add ply:UniquieID() to the timers identifier.
Thanks fixed :D
Sorry, you need to Log In to post a reply to this thread.