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

Humanoid:GetState() not working for some reason?

So I was making my own chat system that if the player typed /e dance the player would play an animation. I also made some events to check if the player was moving. I did try to search but it still doesn't work.

This is the script:

game.ReplicatedStorage.ChatMessage.OnServerEvent:Connect(function(p, msg)
	if msg ~= "/e dance" then
		-- code
	else
		local char = p.Character
		local hum = char.Humanoid
		local anim = char.Animations.Dance
		local track = hum:LoadAnimation(anim)
		if hum:GetState() == Enum.HumanoidStateType.None then
			track:Play()
		end
				
		hum.Jumping:Connect(function(jump)
			if jump then
				track:Stop()
			end
		end)
				
		hum.Died:Connect(function()
			track:Stop()
		end)
				
		hum.FreeFalling:Connect(function(fall)
			if fall then
				track:Stop()
			end
		end)
		
		hum.StateChanged:Connect(function(state)
			if state == Enum.HumanoidStateType.Landed then
				track:Stop()
			end
		end)
		
		hum.StateChanged:Connect(function(state)
			if state == Enum.HumanoidStateType.Freefall then
				track:Stop()
			end
		end)
				
				
		hum.StateChanged:Connect(function(old, new)
			if old == Enum.HumanoidStateType.Climbing then
				track:Stop()
			elseif new == Enum.HumanoidStateType.Climbing then
				track:Stop()
			end
		end)
				
		hum.Running:Connect(function(spd)
			if spd > 0.1 then
				track:Stop()
			end
		end)
				
		hum.Seated:Connect(function(sit)
			if sit then
				track:Stop()
			end
		end)
	end
end)

1 answer

✓ Accepted answer

All you need is the 'StateChanged' to stop the animation since it will occur for every big movements.

1 comment

0

After changing up the script a bit, it works! Thank you.

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