Summary:
Hello, I am trying to make a sprint/animation script but the walking animation wont stop playing when I am trying to play the idle animation. If you could help me it your be appreciated. My animations are all on movement and are mine. My script in is 'StarterCharacterScripts' and is a local script.
Video:
(copy an paste into search)https://gfycat.com/sorrowfulajarbluebottlejellyfish
Code:
local Player = game.Players.LocalPlayer Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() repeat wait() until game.Players.LocalPlayer m = game.Players.LocalPlayer:GetMouse() m.KeyDown:connect(function(key) if key == "0" then local run = Instance.new('Animation') run.AnimationId = 'rbxassetid://5013482632' runAnim = Character.Humanoid:LoadAnimation(run) runAnim:play() Character.Humanoid.WalkSpeed = 20 end end) m.KeyUp:connect(function(key) if key == "0" then runAnim:stop() local walk = Instance.new('Animation') walk.AnimationId = 'rbxassetid://5013378526' walkAnim = Character.Humanoid:LoadAnimation(walk) walkAnim:Play() Character.Humanoid.WalkSpeed = 8 end end) --start of idle animation-- Character.Humanoid.Running:Connect(function(speed) if Character.Humanoid.WalkSpeed < 0.5 then walkAnim:Stop() --turning off walk animation. local idle = Instance.new('Animation') idle.AnimationId = 'rbxassetid://5022482368' local idleAnim = Character.Humanoid:LoadAnimaton(idle) idleAnim:Play() end end
Here is a script that fixes the local variable problem. Also, if this doesn't work, it's likely it is a animation priority problem, try using different priorities to allow specific animations to overwrite others to fix the problem
local Player = game.Players.LocalPlayer local run = local run = Instance.new('Animation')-- naming all the animation local variables up here instead local run = Instance.new('Animation') local idle = Instance.new('Animation') Player = game.Players.LocalPlayer local Character = Player.Character or Player.CharacterAdded:Wait() repeat wait() until game.Players.LocalPlayer m = game.Players.LocalPlayer:GetMouse() m.KeyDown:connect(function(key) if key == "0" then run.AnimationId = 'rbxassetid://5013482632' runAnim = Character.Humanoid:LoadAnimation(run) runAnim:play() Character.Humanoid.WalkSpeed = 20 end end) m.KeyUp:connect(function(key) if key == "0" then runAnim:stop() walk.AnimationId = 'rbxassetid://5013378526' walkAnim = Character.Humanoid:LoadAnimation(walk) walkAnim:Play() Character.Humanoid.WalkSpeed = 8 end end) --start of idle animation-- Character.Humanoid.Running:Connect(function(speed) if Character.Humanoid.WalkSpeed < 0.5 then walkAnim:Stop() --turning off walk animation. idle.AnimationId = 'rbxassetid://5022482368' local idleAnim = Character.Humanoid:LoadAnimaton(idle) idleAnim:Play() end end
Marked as Duplicate by JesseSong and youtubemasterWOW
This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.
Why was this question closed?