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

Is there's a way to determine if player is on idle?

Asked by
RiotGUI 15
4 years ago

Basically, my scenario is: Right when players spawn they get an instant forcefield and it should always be there as long as the player doesn't move. I want to check if the player is not idle anymore to remove the forcefield.

delay(0, function()
    for _, Player in next, Players:GetPlayers() do
        local Character = Player.Character or Player.CharacterAdded:wait()
        Player.Idled:wait()
        if Character:FindFirstChild('ForceField') then
            Character.Forcefield:Remove()
        end
    end
end)

My attempt doesn't work

0
Make sure it was a LocalScript. Xapelize 2658 — 4y
0
maybe you can use a if statement that checks the player x or z position Disnejar 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

You could try to use MoveDirection, which tells us what direction the humanoid is moving in. https://developer.roblox.com/en-us/api-reference/property/Humanoid/MoveDirection

if humanoid.MoveDirection.Magnitude > 0 then
--we are walking
if Character:FindFirstChild('ForceField') then
                Character.Forcefield:Remove()
            end
end
Ad
Log in to vote
0
Answered by 4 years ago

I think you mean something like this:

game.Players.LocalPlayer.Idled:Connect(function()
    print("you idled.")
end)

Answer this question