PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

GetState

This function returns the Humanoid|Humanoid's current Enum/HumanoidStateType.

The humanoid state describes the activity the Humanoid is currently doing, such as jumping or freefalling.

See also

  • To change the Humanoid|Humanoid's state use Humanoid/ChangeState
  • To enable or disable a particular state use Humanoid/SetStateEnabled
  • For more information on the different states available, see Enum/HumanoidStateType

Returns

Return Type Summary

The current Enum/HumanoidStateType of the Humanoid


Code Samples


This code, when placed inside a LocalScript in StarterCharacterScripts|StarterPlayer.StarterCharacterScripts will allow the player’s characters to perform a double jump.

local UserInputService = game:GetService("UserInputService")
local character = script.Parent

local humanoid = character:WaitForChild("Humanoid")

local doubleJumpEnabled = false 

humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Jumping then
		if not doubleJumpEnabled then 
			wait(.2)
			if humanoid:GetState() == Enum.HumanoidStateType.Freefall then
				doubleJumpEnabled = true 
			end
		end
	elseif newState == Enum.HumanoidStateType.Landed then	
		doubleJumpEnabled = false
	end
end)

UserInputService.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.KeyCode.Space then
		if doubleJumpEnabled then
			if humanoid:GetState() ~= Enum.HumanoidStateType.Jumping then
				humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
				spawn(function()
					doubleJumpEnabled = false 
				end)
			end
		end		
	end
end)