Hello, I am making a flash project and I’m having trouble with the animation play. It works but it will not continue after pressing stop and will error before sprinting. Here’s the source code.
local UserInput = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EventsFolder = ReplicatedStorage:WaitForChild("Events")
local Animation = script:WaitForChild("RunAnimation")
local KeyPressed = nil
local Running = nil
local RunGoal = {
FieldOfView = 110
}
local RegularGoal = {
FieldOfView = 110
}
local tweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.1)
local RunTween = tweenService:Create(workspace.CurrentCamera,tweenInfo,RunGoal)
local WalkTween = tweenService:Create(workspace.CurrentCamera,tweenInfo,RegularGoal)
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
UserInput.InputBegan:Connect(function(Key, IsTyping)
if Key.KeyCode == Enum.KeyCode.LeftShift and not IsTyping then
if game.Players.LocalPlayer.Character:WaitForChild("Humanoid").MoveDirection.Magnitude > 0 then
if KeyPressed == nil and Running == nil then
KeyPressed = true
Running = true
LoadAnimation = Humanoid:LoadAnimation(Animation)
LoadAnimation:Play()
EventsFolder:WaitForChild("SpeedOn"):FireServer()
RunTween:Play()
elseif KeyPressed == true and Running == true and not IsTyping then
KeyPressed = nil
Running = nil
LoadAnimation:Stop()
EventsFolder:WaitForChild("SpeedOff"):FireServer()
WalkTween:Play()
end
end
end
end)
Humanoid.Changed:Connect(function()
if Humanoid.Jump and LoadAnimation.IsPlaying and Running == true then
LoadAnimation:Stop()
Running = nil
end
end)
Humanoid.StateChanged:Connect(function(oldState, newState)
if newState == Enum.HumanoidStateType.Landed then
LoadAnimation:Play()
Running = true
end
end)
Humanoid.Running:Connect(function(Speed)
if Speed > 0 and not LoadAnimation.IsPlaying and Running == nil then
LoadAnimation:Play()
RunTween:Play()
Running = true
elseif Speed <= 0.01 and LoadAnimation.IsPlaying and Running == true then
LoadAnimation:Stop()
WalkTween:Play()
Running = nil
end
end)
Output
Video
[You can clearly see the flaws of this script]

there is an animation ID. look at the output


