I am making a wall climbing system and I have gotten it to a point where I have no clue how to fix it. Basically right now it is able to detect when there is a climbable wall, and it can change the state of the humanoid, the problem is that it flicks the player to the climbing state, but instantly switches it back to the running state, and I am unsure how to fix this.
-- ServerScriptService - WallClimbServerScript
local WallClimbEvent = game:GetService("ReplicatedStorage").Events.WallClimbEvent
local climbingPlayers = {}
WallClimbEvent.OnServerEvent:Connect(function(player)
local character = player.Character
if character then
local humanoid = character:WaitForChild("Humanoid")
local function checkIfClimbable(part)
return part:IsA("BasePart") and part:GetAttribute("Climbable")
end
local rootPart = character:WaitForChild("HumanoidRootPart")
rootPart.Touched:Connect(function(touchedPart)
if checkIfClimbable(touchedPart) then
humanoid:ChangeState(Enum.HumanoidStateType.Climbing)
climbingPlayers[player.UserId] = true -- Track climbing state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false) -- Disable running
end
end)
humanoid.StateChanged:Connect(function(_, newState)
if newState == Enum.HumanoidStateType.Climbing then
climbingPlayers[player.UserId] = true -- Track climbing state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false) -- Disable running
else
climbingPlayers[player.UserId] = nil -- Reset climbing state
humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true) -- Re-enable running
end
end)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
climbingPlayers[player.UserId] = nil -- Clear climbing state when player leaves
end)