I want to check when the player is idle for 5 seconds (not jumping not using WASD or arrow keys) and after that to run a code. I tried with User Input Service (with InputBegan and Ended), but if a player is holding more than one key (W and A for an example) and releases one of them the idle script will run thinking he is idle when he is not.
isWalking = true
--the input began event
uis.InputBegan:Connect(function(input, typing)
if not typing and input.UserInputType == Enum.UserInputType.Keyboard and (input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.A --[[..etc]]) then
isWalking = true
end
end)
--the input ended event
uis.InputEnded:Connect(function(input, typing)
if not typing and input.UserInputType == Enum.UserInputType.Keyboard and (input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.S or input.KeyCode == Enum.KeyCode.A or input.KeyCode == Enum.KeyCode.D or input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.Up or input.KeyCode == Enum.KeyCode.Down)then
isWalking = false
wait(5)
if isWalking == false then
--code
end
end
end)
Does anyone know how could I make it work out properly?

2 comments
You could use this instead -> http://wiki.roblox.com/index.php?title=API:Class/Humanoid/Running
Should of mentioned I first tried it with the Humanoid's Running event. It had a similar effect, as if you start running before 5 seconds have passed and if you remain at constant speed the code will run unless something affects your speed. If nothing else works I may stick to that.