Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

StateChanged won't work?

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

✓ Accepted answer

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)

1 comment

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.