Last year I asked how to make it so It prints when the player isn't jumping or walking so I used Idle event like this
game.Players.Player.Idled:connect(function(time)
print("Player has been idle for " .. time .. " seconds")
end)
I just wanted to make a script that kills a player if they stay still for 5 seconds. Here is my attempt.
IdleTime = 5
game.Players.PlayerAdded:connect(function(plyr)
plyr.CharacterAdded:connect(function(char)
char.Humanoid.Running:connect(function()
wait(IdleTime)
char.Humanoid.Running:connect(function(speed)
if speed == 0 then
char.Humanoid.Health = 0
end
end)
end)
end)
end)
It works but it's a little glitchy, like if they stay still then move for a little then stay still they immediately die.
Answer
player = game.Players.LocalPlayer
repeat wait(0) until player.Character
character = player.Character
humanoid = character:WaitForChild("Humanoid")
MaxIdleTime = 5
CurrentIdleTime = MaxIdleTime
humanoid.Running:connect(function()
CurrentIdleTime = MaxIdleTime
end)
repeat
CurrentIdleTime = CurrentIdleTime - 1
wait(1)
until CurrentIdleTime <= 1
humanoid.Health = 0

4 comments
I edited your script and made it better since the way you did it it would actually take 6 seconds instead of 5. I fixed it and removed some parts of it.
It still glitches a little though.
Well this script makes it so if you keep moving nonstop for 5 seconds, then it would kill you. Is that considered the "glitch"?
Yep