1

# StateChanged won't work?

emite1000 335
7 years ago

While the character is in the middle of walking, I have this script run:

Plyr = game.Players.LocalPlayer.Character.Humanoid
Plyr.StateChanged(None):connect(function()
script.Disabled = true
end)


But when it tries to run, it just gives the error: attempt to call field 'Running' (a userdata value) (line 1).

What is wrong with this?

0
7 years ago

What this looks like to the Lua interpreter is you are attempting to call the 'StateChanged' member of the Humanoid with the argument 'None', which is nil in this context, and then call the result's 'connect' method. Since StateChanged is an Event and not a Method, this breaks there.

What I assume you meant, is you want this to fire when the State changes to 'None':

Plyr = game.Players.LocalPlayer.Character.Humanoid
Plyr.StateChanged:connect(function(state)
if state == Enum.HumanoidStateType.None then
script.Disabled = true
end
end)

0
Actually I just needed it to fire when the State changed to anything at all. None was just being specific (but not necessary). My problem was that even when I was using nothing after StateChanged, I had empty parentheses there (which needed to be removed for the script to work). Looking at your script made me realize that, so thanks! emite1000 335 — 7y