I have tested, and tried different ways of trying to detect if a Player is Idle, but, sadly, to my surprise, the code works, but, it does not work after second execution of the chunk, and because of this, I am clearly confused. Sadly I can not provide Output, because nothing came up, as well as the debugging prints stopped, well, printing after the first execution of the chunk. Here is the code I am currently using;
repeat wait() until game.Players.LocalPlayer
local plr = game.Players.LocalPlayer;
repeat wait() until plr.Character and plr.Character:FindFirstChild("Torso")
local torso = plr.Character.Torso;
local chkPosEvery = 1/13.37;
repeat
local firstPos = torso.Position.X --Yes, I've tried 'CFrame', and Regular 'Position', but this seemed to detect it better
wait(chkPosEvery)
if torso.Position.X == firstPos then
if plr.Character:FindFirstChild("ForceField") then
return false, print("ForceField already existant, don't spam")
end
local FF = Instance.new("ForceField",plr.Character)
print("I redeem you AFK")
else
print("You are no longer AFK")
for i,FF in pairs(plr.Character:GetChildren()) do
if FF:IsA("ForceField") then
FF:Destroy()
end
end
end
until nil

4 comments
Im sure ROBLOX has a service for this.. Or at least I think there is.
There is, however, on the WIKI it says (for this event of the Humanoid for a Player being 'Idle'), it fires two minutes after from the Player going Idle.
You can use the running event to see if the player's Torso/HumanoidRootPart has not been moving...
https://scriptinghelpers.org/questions/15035/how-would-i-make-a-convenient-idle-player-kill-script