Hello, good evening (or morning idk).
I’m making a sprint script, and I thought everything was working fine until I found a weird bug in the animation.
- What do you want to achieve?
The idea is that the animation plays only when the player is moving (walking), and later I want to make it so that the animation stops when you jump (I’m too lazy to figure out how to do that yet).
- What is the issue?
The issue is that when another animation (Jump, fall, etc.) plays, the running animation will continue even if I’m no longer holding shift.
- What solutions have you tried so far?
I tried using while loops that stop the animation when the player is not holding down shift. But I think I might have used the loops the worng way (Or maybe I shouldn’t be using them in the first place)
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
local WalkSpeedToReach = 25
local OriginalWalkSpeed = Humanoid.WalkSpeed
local UIS = game:GetService("UserInputService")
local Walking = script:WaitForChild("Walking") -- Value
local Running = script:WaitForChild("Running")
local RunAnim = Humanoid:LoadAnimation(script.RunAnim)
local WalkAnim = Character.Animate.walk.WalkAnim
local WalkAnimId = WalkAnim.AnimationId
UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then -- Detect if shift input started
if script.Walking.Value == true and Character.Humanoid.MoveDirection.Magnitude > 0 then -- See if Walking = true
Humanoid.WalkSpeed = OriginalWalkSpeed + (WalkSpeedToReach - OriginalWalkSpeed) -- Change speed
WalkAnim.AnimationId = script.RunAnim.AnimationId
Humanoid:LoadAnimation(WalkAnim)
RunAnim:Play()
RunAnim:AdjustSpeed(1.5)
Running.Value = true
end
end
end)
UIS.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then -- Detect if shift input ended
Humanoid.WalkSpeed = Humanoid.WalkSpeed - (WalkSpeedToReach - OriginalWalkSpeed) -- Change speed
RunAnim:Stop()
WalkAnim.AnimationId = WalkAnimId
Humanoid:LoadAnimation(WalkAnim)
Running.Value = false
end
end)
while true do
if Character.Humanoid.MoveDirection.Magnitude > 0 then -- Set walking to true or false
Walking.Value = true
--print("True")
else
Walking.Value = false
RunAnim:Stop()
print("Stopped")
end
if Running.Value == false then
RunAnim:Stop()
WalkAnim.AnimationId = WalkAnimId
--Humanoid:LoadAnimation(WalkAnim)
print("Stopped Running")
end
wait(.0000000000001)
end
robloxapp-20220606-1551038.wmv (2.9 MB)
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.