Is there a way to detect when a player is Idle from a server script?

Hello! As the title says, the “player.Idled” event doesn’t seem to work in a server script, here is my script:

game.Players.PlayerAdded:Connect(function(plr)
	plr.Idled:Connect(function()
		print(plr.Name .. " is idle")
	end)
end)

But even when the player is Idle, nothing prints. I’ve tried looking into other topics, for example this one: How would I detect if a player is AFK?

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.

Any help is appreciated!

1 Like

Use magnitude to see if player has moved at all

1 Like

From what I know, I don’t know, sorry.

Alright, I will script that and get right back to you with my script.

1 Like

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)

Thank you again!

3 Likes