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)