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

Why is the StateChanged event not detecting running stops?

Asked by 10 years ago

Hello, I am practising using the StateChanged event of Humanoid instead of the old Running and Jumping events. I have got the running and jumping working, but whenever I stop running, the StateChanged event doesn't fire and my 2D morph is left running on the spot. The jumping state changes the values to go to the idle decal, but the running one doesn't change at all.

Anyone have an explanation for this?

EDIT: The running event also occurs randomly when I'm idle after jumping. I'm guessing this is because of how the ROBLOX character now works, and it's kind of frustrating.

Any help is appreciated, thanks!

Code snippet (jumping and running variables are defined earlier in the script):

function State(state)
    print("State Change: "..tostring(state)) --Just to check if it was working.
    if state == Enum.HumanoidStateType.FallingDown or state == Enum.HumanoidStateType.Jumping or state == Enum.HumanoidStateType.Freefall then
        print("Jumping") --We're jumping
        jumping = true
        running = false
    elseif state == Enum.HumanoidStateType.Running or state == Enum.HumanoidStateType.RunningNoPhysics then
        print("Running") --We're running
        jumping = false
        running = true
    else
        print("Idle") --We go to idle after jumping, but not after running. Why?
        jumping = false
        running = false
    end
end
0
I noticed there are a lot of HumanoidStateType enums that aren't defined here. Maybe try to define all of them, and instead of just an "else" at the end, have "elseif state == Enum.HumanoidStateType.None" (Plus anything else you want to trigger both as false). I get the feeling that something is confusing the system with the lack of frequent events not being defined. RoboFrog 400 — 10y
0
That didn't work. I know the Jump one works because the state type is Landed, which would fire the last else, but I don't see why ROBLOX haven't made an Idle state type (unless it's a bug). Spongocardo 1991 — 10y
0
Hmm... I would think that "None" would be equivalent to idle, but apparently not. At this point, my only suggestion would be making a test script which will print your current state whenever it changes, and look carefully at what your state becomes after you stop walking or running (since there's apparently a difference). Maybe that'll shed some light on the situation. RoboFrog 400 — 10y
0
I've checked, there's either no state for standing still or the state is broken. The landed state activates the idle after the jump, but the run state doesn't change to anything and stays on the run state. This is quite odd. Spongocardo 1991 — 10y

Answer this question