How to define the state type of a humanoid?

So, i’m currently learning some new stuff about roblox scripting and i’ve got to a topic where it talks about “Humanoid State Type” and decided to experiment myself. At first i was trying to make a print statement when the humanoid is currently in that state type, i wanted to apply this for swimming, but i couldn’t find the keyword for it anywhere.

Anyway here’s my code:

local humanoid = game.Workspace:WaitForChild("Qapandt").Humanoid

	if humanoid.WhatsTheKeyword == Enum.HumanoidStateType.Swimming then --here
		print("Player is swimming")

humanoid:GetState() is what you’re looking for.

Also, the old and new state are parameters of the StateChanged event, so you can do the following:

humanoid.StateChanged:Connect(function(old, new)
	print("Humanoid state changed from", old, "to", new)

In general, you can also check the documentation page that lists all the properties, methods and events of a class with their related information.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.