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)

1 comment
Maybe try using elseif? You're not using elseif anywhere and maybe that's causing the delay.