But again, the script that has been provided as an answer has a “LocalPlayer” in it, meaning it’s used in a local script. Which I do not want to use as it’s safer to do all this process in a server script since I’m using it to detect if the player is afk, they won’t recieve coins, and if there are no longer afk. They start receiving coins again.
Thank you for reminding me to use this method! This is the script that I’ve scripted in order for it to work:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
local TimePlayerHasBeenIdle = 0
while wait() do
wait(1)
if math.floor(char:WaitForChild("HumanoidRootPart").Velocity.magnitude) == 0 then
TimePlayerHasBeenIdle = TimePlayerHasBeenIdle + 1
if TimePlayerHasBeenIdle >= 10 then
print(player.Name.." has been idle for "..TimePlayerHasBeenIdle.." seconds")
end
else
TimePlayerHasBeenIdle = 0
end
end
end)
end)