Hello, I'm currently working on disabling the running script while im crouching. I've tried everything i know of but i cant do it.
Here are the scripts :
Running script
local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
repeat wait() until game.Players.LocalPlayer
local m = game.Players.LocalPlayer:GetMouse()
m.KeyDown:connect(function(key)
if key == "0" then --"Shift to run" 0 == shift
print("Running")
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 16 --change "25" to your speed you want
end
end)
m.KeyUp:connect(function(key)
if key == "0" then
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 10 --change "16" to your speed you want when you stop running
end
end)
Crouching script
local Char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local UIS = game:GetService('UserInputService')
local IsCrawling = false
local CrouchDownAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchDown"))
local CrouchingAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("Crouching"))
local CrouchUpAnimation = Humanoid:LoadAnimation(game.ReplicatedStorage.ClientAnimations:WaitForChild("CrouchUp"))
local cancrawl = false
local topspeed = 12
Humanoid.Running:Connect(function(speed2)
if speed2 > topspeed then
cancrawl = false
elseif speed2 < topspeed then
cancrawl = true
Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
if Humanoid.FloorMaterial == Enum.Material.Air then
cancrawl = false
elseif Humanoid.FloorMaterial ~= Enum.Material.Air then
cancrawl = true
end
end)
Humanoid.Running:Connect(function(speed)
if speed > 0 then
CrouchingAnimation:AdjustSpeed(1)
else
CrouchingAnimation:AdjustSpeed(0)
end
end)
UIS.InputBegan:Connect(function(input,gameprocessed)
if speed2 > topspeed then return end
if gameprocessed then return end
if not cancrawl then return end
if input.KeyCode == Enum.KeyCode.C then
if not IsCrawling then
IsCrawling = true
cancrawl = false
CrouchDownAnimation:Play()
wait(0.25)
CrouchDownAnimation:Stop()
CrouchingAnimation:Play()
CrouchingAnimation:AdjustSpeed(0)
Humanoid.WalkSpeed = 5
game.StarterPlayer.CharacterJumpPower = 0
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
if IsCrawling then
IsCrawling = false
cancrawl = true
CrouchingAnimation:Stop()
CrouchUpAnimation:Play()
wait(0.25)
CrouchUpAnimation:Stop()
Humanoid.WalkSpeed = 10
game.StarterPlayer.CharacterJumpPower = 0
end
end
end)
end
end)

1 comment
Thanks i'll try this