Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How come my 'Idle' code isn't detecting a Player being Idle after first execution?

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

0

Im sure ROBLOX has a service for this.. Or at least I think there is.

0

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.

0

You can use the running event to see if the player's Torso/HumanoidRootPart has not been moving...

1 answer

Replace "repeat" with "while wait(1) do"

and "until nil" with "end"

1 comment

0

Their both Loop keywords.

This discussion is preserved as it was. New answers, comments, and votes are closed.