What i’m trying to do is to make a sprint and crouch system, it does work, but you can crouch and sprint at the same time.
Code for both (in StarterGui)
local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local Character = player.Character
repeat wait() until Character
local button = script.Parent:WaitForChild('Mobile')
local Humanoid = Character:WaitForChild("Humanoid")
local isRunning = false
local Animation = Humanoid:LoadAnimation(script:WaitForChild("Walk"))
Humanoid.Running:Connect(function(speed)
if speed > 0 then
Animation:AdjustSpeed(1)
else
Animation:AdjustSpeed(0)
end
end)
function Crouch()
if not isRunning then
isRunning = true
Animation:Play()
Humanoid.JumpPower = 0
Humanoid.HipHeight = -1
Humanoid.WalkSpeed = 7.5
wait(1)
elseif isRunning then
isRunning = false
Animation:Stop()
Humanoid.JumpPower = 0
Humanoid.HipHeight = 0
Humanoid.WalkSpeed = 12
wait(1)
end
end
UserInputService.InputBegan:Connect(function(key)
if key.KeyCode == Enum.KeyCode.C then
Crouch()
end
end)
if UserInputService.TouchEnabled then
button.Visible = true
end
button.MouseButton1Down:Connect(Crouch)
local UIS = game:GetService('UserInputService')
local TS = game:GetService("TweenService")
local Sprint = script.Parent:WaitForChild('Sprint')
local Bar = Sprint:WaitForChild('Bar')
local Stamina = Sprint:WaitForChild('TextLabel')
local cam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local NormalWalkSpeed = 10
local NewWalkSpeed = 28
local ii = 10
repeat wait() until game.Players.LocalPlayer.Character
--// FUNCTIONS \\--
UIS.InputBegan:connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
TS:Create(player.Character.Humanoid, TweenInfo.new(2), {WalkSpeed = NewWalkSpeed}):Play()
running = true
while ii > 0 and running do
ii = ii - .045
TS:Create(Stamina, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {TextTransparency = 0}):Play()
TS:Create(Sprint, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {BackgroundTransparency = 0}):Play()
TS:Create(Bar, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {BackgroundTransparency = 0}):Play()
Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .5, true)
wait()
if ii <= 0 then
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
end
end
end
end)
UIS.InputEnded:connect(function(key, gameProcessed)
if key.KeyCode == Enum.KeyCode.LeftShift and gameProcessed == false then
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
running = false
while ii < 10 and not running do
ii = ii + .025
Bar:TweenSize(UDim2.new(ii / 10, 0, 1, 0), 'Out', 'Quint', .1, true)
wait()
if ii <= 0 then
TS:Create(player.Character.Humanoid, TweenInfo.new(1.25), {WalkSpeed = NormalWalkSpeed}):Play()
end
if ii >= 10 and not running then
TS:Create(Stamina, TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.Out, 0, false, 0), {TextTransparency = 1}):Play()
TS:Create(Sprint, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {BackgroundTransparency = 1}):Play()
TS:Create(Bar, TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 0), {BackgroundTransparency = 1}):Play()
end
end
end
end)
If anyone can help the player not crouch at the speed of Mach 1, it would be much appreciated.