How to detect if Player is climbing?

Hello! For my punch function for my game, I want the player to not be able to punch whilst they are climbing. I tried implementing this to my code:

local CurrentState = Enum.HumanoidStateType.Running

Humanoid.StateChanged:Connect(function(_,new)
	CurrentState = new.EnumType
end)
if CurrentState ~= Enum.HumanoidStateType.Climbing then

However, it still does the punch wilst the player is climbing.

Here is the entire script:

local Players = game:GetService("Players")
local LPlr = Players.LocalPlayer
local char = LPlr.Character or LPlr.CharacterAdded:Wait()
local Animator = char:WaitForChild("Humanoid"):FindFirstChildWhichIsA("Animator")
local ImputS = game:GetService("UserInputService")
local RepStore = game:GetService("ReplicatedStorage")
local kEvent = RepStore.Events.KnockbackM
local Mouse = LPlr:GetMouse()
local AnimationID = "rbxassetid://8388173238"
local KC = Enum.KeyCode.P
local Humanoid = char:FindFirstChildWhichIsA("Humanoid")

local CurrentState = Enum.HumanoidStateType.Running

Humanoid.StateChanged:Connect(function(_,new)
	CurrentState = new.EnumType
end)



ImputS.InputBegan:Connect(function(InputO) if InputO.KeyCode == KC then local suc, err = pcall(function()
			if CurrentState ~= Enum.HumanoidStateType.Climbing then
				local Tar = Mouse.Target 
				local Animation = Instance.new("Animation")
				Animation.AnimationId = AnimationID
				local punch = Animator:LoadAnimation(Animation)
				punch:Play()
				if Tar and Tar.Parent:FindFirstChild("Humanoid") then
					kEvent:FireServer(Tar.Parent.PrimaryPart)
				end
			end
		end) if not suc then warn(err) end
	end
end)

Been 21 days and I still can’t find how to detect if player is climbing.

1 Like

This only got the category the Enum belonged to, just do:

Humanoid.StateChanged:Connect(function(_, new)
	CurrentState = new
end)

It stores the Enum rather than the category.

Edit: To add onto this, you don’t really need an event either. You can just call Humanoid:GetState() and check if the state isn’t Enum.HumanoidStateType.Climbing

3 Likes