Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 9 years ago

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
0
Im sure ROBLOX has a service for this.. Or at least I think there is. MessorAdmin 598 — 9y
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. TheeDeathCaster 2368 — 9y
0
You can use the running event to see if the player's Torso/HumanoidRootPart has not been moving... EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

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

and "until nil" with "end"

0
Their both Loop keywords. TheeDeathCaster 2368 — 9y
Ad

Answer this question