Ad
Log in to vote
1

StateChanged won't work?

Asked by
emite1000 335 Moderation Voter
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?

2 answers

Log in to vote
0
Answered by
adark 5477 Badge of Merit Moderation Voter Community Moderator
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
Ad
Log in to vote
0
Answered by 7 years ago

StateChanged event is a member of the Humanoid, and cannot be used with the player. At least I don't think it can. http://wiki.roblox.com/index.php?title=StateChanged_(Event)

0
Oh sorry I'm an idiot, I didn't post what I have Plyr defined as. Plyr = game.Players.LocalPlayer.Character.Humanoid emite1000 335 — 7y
0
Ah, lol xD LunaScripter 80 — 7y

Answer this question