• CurTime wont work unless I'm just bad
    2 replies, posted
I have coded something so when someone spawns it will god them. I have a var set to curtime + 30 but it seems to never work when its == curtime. It gets to the first part but not the last part. Any help would be appreciated. [code] local timeLeftForASK = 0 local function spawnProt( ply ) print( "A Players ASK Started" ) ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] You have 30 seconds of spawn protection.\n" ) ply:GodEnable() timeLeftForASK = CurTime()+30 if timeLeftForASK == CurTime() then print( "A Players ASK Ended" ) ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] Your spawn protection has ended.\n" ) ply:GodDisable() end end hook.Add( "PlayerSpawn", "Anti-Spawn-Kill", spawnProt ) [/code]
[QUOTE=Bkamahl;51744122]I have coded something so when someone spawns it will god them. I have a var set to curtime + 30 but it seems to never work when its == curtime. It gets to the first part but not the last part. Any help would be appreciated. [code] local timeLeftForASK = 0 local function spawnProt( ply ) print( "A Players ASK Started" ) ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] You have 30 seconds of spawn protection.\n" ) ply:GodEnable() timeLeftForASK = CurTime()+30 if timeLeftForASK == CurTime() then print( "A Players ASK Ended" ) ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] Your spawn protection has ended.\n" ) ply:GodDisable() end end hook.Add( "PlayerSpawn", "Anti-Spawn-Kill", spawnProt ) [/code][/QUOTE] As soon as a player spawns, the function spawnProt() is called, when spawnProt() is called, and the if statement is evaluated, CurTime() is not equal to CurTime() + 30. The way you would do it is to replace the if statement with a timer. [code] timer.Simple(30, function() print("A player's ASK Ended") ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] Your spawn protection has ended.\n" ) ply:GodDisable() end) [/code] tl;dr you're bad.
[QUOTE=Apickx;51744153]As soon as a player spawns, the function spawnProt() is called, when spawnProt() is called, and the if statement is evaluated, CurTime() is not equal to CurTime() + 30. The way you would do it is to replace the if statement with a timer. [code] timer.Simple(30, function() print("A player's ASK Ended") ply:PrintMessage( HUD_PRINTTALK, "[A.S.K] Your spawn protection has ended.\n" ) ply:GodDisable() end) [/code] tl;dr you're bad.[/QUOTE] Yeah I am bad dont know why I didnt think of that thanks ;3
Sorry, you need to Log In to post a reply to this thread.