What do you want to achieve? Keep it simple and clear!
Hi, I go by Restored or Carisard, I would like to know how I would go about creating a script that checks if a player for example has / has not walked in the last 3 seconds. If this is anything you can help with, then I would really appreciate your help.
What is the issue? Include screenshots / videos if possible!
I guess that I can not figure it out?
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I found a post on devforum with a similar problem but still not similar enough so I tried changing the code up a bit but still couldn’t get it to work, can not find anything on the Developer Hub either.
Usages of os.time() which acts as a timer and RunService.Heartbeat event acts as a repetitive loop to check the difference between the initial time and the current time can help you.
local run = game:GetService("RunService")
local userInput = game:GetService("UserInputService")
local lastActivity = tick()
run.RenderStepped:Connect(function()
if tick() - lastActivity > 3 then
print("Player is inactive!")
end
end)
userInput.InputChanged:Connect(function(input)
lastActivity = tick()
end)
You can listen for user input to determine if a user hasn’t performed an action for 3 or more seconds.
I think you should use the InputBegan event because if you use InputChanged event, it will fire only when input type changed, so if player is just moving their mouse and nothing else, it will still count as no activity.