-
What do you want to achieve?: Im trying to make a running system which winds up the run and when you reach max speed, plays an animation.
-
What is the issue?: The Animation doesn’t play, but isPlaying returns true
-
What solutions have you tried so far?: The animation is made by me, i tried setting its priority to “Action”, I’ve tried playing it in a local script but nothing worked
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local FunctionsFolder = ReplicatedStorage:WaitForChild("Functions")
local StartRunFunction = FunctionsFolder:WaitForChild("StartRun")
local StopRunFunction = FunctionsFolder:WaitForChild("StopRun")
local movement = {}
local runAnimID = "rbxassetid://17705765971"
local isRunning = false
local runLoop = coroutine.create(function(player)
local humanoid = player.character:FindFirstChildOfClass("Humanoid")
assert(humanoid, "No Humanoid found!")
local animator = humanoid:FindFirstChildOfClass("Animator")
assert(animator, "No Animator found!")
local runAnim = Instance.new("Animation")
runAnim.AnimationId = runAnimID
runAnim.Parent = player.character
local track = animator:LoadAnimation(runAnim)
while true do
if isRunning then
humanoid.WalkSpeed = humanoid.WalkSpeed + 7
if humanoid.WalkSpeed >= 64 then
humanoid.WalkSpeed = 64
if track and not track.IsPlaying then
track:Play()
print(track.IsPlaying)
end
end
print(humanoid.WalkSpeed)
wait(0.3)
else
humanoid.WalkSpeed = humanoid.WalkSpeed - 20
if humanoid.WalkSpeed <= 16 then
humanoid.WalkSpeed = 16
if track and track.IsPlaying then
track:Stop()
end
coroutine.yield()
else
wait(0.3)
end
end
end
end)
function movement.StartRun(player)
isRunning = true
coroutine.resume(runLoop, player)
end
StartRunFunction.OnServerInvoke = movement.StartRun
function movement.StopRun(player)
isRunning = false
end
StopRunFunction.OnServerInvoke = movement.StopRun
return movement