Hello! I am trying to make a sprinting system for my boss fighting game and came across an issue. For some reason, the walkspeed won’t change back to 16 when you stop holding shift.
Here’s the code:
wait(.5)
local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15268336493"
local animtrack = humanoid:LoadAnimation(animation)
local debouncewait = false
local debounce = 2
game.UserInputService.InputBegan:Connect(function(input, gpe)
if input.KeyCode == Enum.KeyCode.LeftShift then
player.Character.Humanoid.WalkSpeed = 20
end
end)
game.UserInputService.InputEnded:Connect(function(input, gpe)
local stunned = player.Character:GetAttribute("Stunned")
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if debouncewait == false and stunned == false or debouncewait == false and stunned == nil then
debouncewait= true
print(stunned)
print("clicked")
animtrack:Play()
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash1remote:FireServer()
wait(0.25)
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash2remote:FireServer()
wait(0.25)
game.ReplicatedStorage.slashsfx:Play()
game.ReplicatedStorage.slash3remote:FireServer()
wait(debounce)
debouncewait = false
end
end
if input.KeyCode == "LeftShift" then
player.Character.Humanoid.WalkSpeed = 16
end
end)```