#humanoid.statechanged not working with modulescript (solved)

1 messages · Page 1 of 1 (latest)

sharp oxide
#
function PlayerClient:IsState(State)

    Humanoid.StateChanged:Connect(function(_OldState,NewState)

        if NewState == State then
            
            return true
        end    
    end)    
end

function PlayerClient:IsRunning()

    if PlayerClient:IsState(Enum.HumanoidStateType.Running) then

        return true
    end
end    
#
while task.wait() do
        
        if PlayerClient:IsRunning() then
            
            print("YABBADABBA")
            
        end
#

doesnt print anything

#
function PlayerClient:isrunning()
    
    if Humanoid.MoveDirection.Magnitude > 0 then
        
        return true
    end
end
sharp oxide
#

id rather use humanoid states though

sharp oxide
#

the other code snippets are in modules

fair plover
#

So you're returning from the connection's scope, not the actual accessor scope. All the accessor is doing is generating new connections to StateChanged.

#

What you should do instead is have

currentHumanoidState = Enum.HumanoidStateType.None
Humanoid.StateChanged:Connect(function(old,new)
  currentHumanoidState = new
end)

and then in the accessor, you can compare the State parameter to currentHumanoidState, and this should yield your intended result

#

full implementation

currentHumanoidState = Enum.HumanoidStateType.None
Humanoid.StateChanged:Connect(function(old,new)
  currentHumanoidState = new
end)

function PlayerClient:IsState( State )
  return State == currentHumanoidState
end

function PlayerClient:IsRunning()
  if PlayerClient:IsState(Enum.HumanoidStateType.Running) then
    return true
  end
end
#

or even better

function PlayerClient:IsRunning()
  return PlayerClient:IsState(Enum.HumanoidStateType.Running)
end
sharp oxide
#

I'll try this out later after I come back

sharp oxide
#

this works thanks

#

too bad the default humanoid states are broken

#

.running fires even when standing still

#

ill just do that using humanoid.movedirection then

fair plover
#

but yea movedirection works fine

sharp oxide
#

oh theres a speed parameter for it?

#

aight