I'm trying to make an animation script for being idle and walking. I know that I can change the default animation, but I'm looking to do something else with this. My problem is that there's a delay between the player moving and the animation playing. I'm also using a script inside ServerScriptService instead of a local script because I don't think a local script would animate on both client and server(if it does please let me know). If it's because of an issue with the animation itself, please let me know and I'll fix that.
game.Players.PlayerAdded:Connect(function(plr) repeat wait() until plr.Character local char = plr.Character local Humanoid = char.Humanoid local idle = Instance.new("Animation") idle.AnimationId = "rbxassetid://7052225614" local idletrack = Humanoid:LoadAnimation(idle) local move = Instance.new("Animation") move.AnimationId = "rbxassetid://7052226982" local movetrack = Humanoid:LoadAnimation(move) local function playAnimation(animName) if animName == "move" then movetrack:Play() end if animName == "idle" then idletrack:Play() end end local function stopAnimation(animName) if animName == "move" then movetrack:Stop() end if animName == "idle" then idletrack:Stop() end end playAnimation("idle") --To load it when the player spawns Humanoid.Running:Connect(function(speed) if speed > 0 then if not movetrack.IsPlaying then stopAnimation("idle") playAnimation("move") end else if speed == 0 then if not idletrack.IsPlaying then stopAnimation("move") playAnimation("idle") end end end end) end)
game.Players.PlayerAdded:Connect(function(plr) repeat wait() until plr.Character local char = plr.Character local Humanoid = char.Humanoid local idle = Instance.new("Animation") idle.AnimationId = "rbxassetid://7052225614" local idletrack = Humanoid:LoadAnimation(idle) local move = Instance.new("Animation") move.AnimationId = "rbxassetid://7052226982" local movetrack = Humanoid:LoadAnimation(move) local function playAnimation(animName) if animName == "move" then movetrack:Play() elseif animName == "idle" then idletrack:Play() end end local function stopAnimation(animName) if animName == "move" then movetrack:Stop() elseif animName == "idle" then idletrack:Stop() end end playAnimation("idle") --To load it when the player spawns Humanoid.Running:Connect(function(speed) if speed > 0 then if not movetrack.IsPlaying then stopAnimation("idle") playAnimation("move") end elseif speed == 0 then if not idletrack.IsPlaying then stopAnimation("move") playAnimation("idle") end end end) end)
There.
Fixed thanks to the comments and almost answer. The delay is mostly gone, but a slight delay is fine. I needed to add elseifs to the functions but not the Humanoid.Running.