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

How do I detect my if the player isn't moving (Idle)?

Asked by 6 years ago

Hi guys, how would i go about finding out if a character is idling or not? GetState() doesn't return an "Idle" state when a player is stationary. It returns "RunningNoPhysics" back to me, which i cannot use because while running, Getstate() will return both "RunningNoPhysics" and "Running" in intervals. There are 2 ways I've thought about.

1) Use 2 variables to find out the distance between the new and old position of the humanoidRootPart, on all 3 axis (X,Y,Z) so i will have a total of 6 variables, 1 old and 1 new for each axis. After that, grab the difference and make sure all 3 differences = 0 (Means not moving).

2) While running, i realised GetState() will only return between 200-300 "RunningNoPhysics". I will look more >300 "RunningNoPhysics" and decide if the player is moving or not.

I should also place the above 2 suggestions in a "spawn (function()end)" to keep the calculation constantly updated. Are there any better methods to deal with this? I can't seem to get "humanoid.Running:connect()" working. It got skipped even when I'm running..

3 answers

Log in to vote
0
Answered by 6 years ago

There is an event for players called Player.Idled()

0
This seems like a possibility, but say if I move my mouse won't that reset the counter? Cause I want to play the Idle animation when the player is not moving. Meaning while he sorts his inventory and stuff, the Idle animation should still be playing. lesliesoon 86 — 6y
0
The mouse has an event called Idle() which can work too User#19524 175 — 6y
0
oh ok so i gotta use a combination of both idles? This is getting a lot more complicated than I've expected. lesliesoon 86 — 6y
Ad
Log in to vote
0
Answered by
hellmatic 1523 Moderation Voter
6 years ago
Edited 6 years ago

Another method:

game.Workspace.Player.Humanoid.Running:connect(function(speed)
    if speed > 0 then
        print("Player is running") -- player is walking
    else
        print("Player has stopped") -- player is idle
    end
end)
0
mm, I've stated that this method doesnt seem to work for me for some reason. Regardless I"ll try it again tomorrow. lesliesoon 86 — 6y
Log in to vote
0
Answered by 4 years ago

hmm, have a script that will detect every possible thing that can make a player move, like ckeck if the player is holding w, a, s or d, spacebar and have that connect to a module. Also every single code u make that will move the character like press e near a bed to sleep should connect to a module. The module should have the following code:

local animator = {}
local humanoidRoot = script.Parent.HumanoidRootPart

animator.Moving = function()
    local pos = humanoidRoot.Position
    wait()
    while pos ~= humanoidRoot.Position do wait() pos = humanoidRoot.Position end
    wait(**however much time u wanna wait for the animation**)
    script.Parent.Humanoid:LoadAnimation(animation):Play()
end

return animator

Make sure the animation is an idle animation, idk much about animations but I think their own idle animation will play over your animation otherwise, but dont have it more than idle because otherwise it might play over their walking animation. And don't forget to put the module script in starter character scripts.

P.S. I haven't tried to do this with a player but im pretty sure this will work ;)

0
Hey I just realised that this post is from over a year ago, I hope you have made something that works! YourM4ster 15 — 4y

Answer this question