I have a script that places the player in control of a custom character with a walking and idle animation. I'm trying to have the walking animation change based on the status of a string value. When I change the string value, Instead of playing the alternate walking animation, the character just plays the idle animation. Thanks for any help.
wait(1) local player while not player do wait() player = game:GetService('Players').LocalPlayer end function onSpawn() local char = game.ReplicatedStorage["New Player"]:Clone() local SpawnLocation = game.Workspace.SpawnLocation char.Parent = workspace char.Name = player.Name char:MoveTo(SpawnLocation.Position) local prevChar = player.Character wait() player.Character = char prevChar:Destroy() if char:FindFirstChild("Humanoid") then char.Humanoid:Destroy() end local human = Instance.new("Humanoid", char) char.Archivable = false human.WalkSpeed = 8 human.Died:connect(function() wait(1) onSpawn() wait(.1) player.Character.Humanoid.Running:connect(onGround) end) --Player Values local move_left = false local move_right = false local already_ran = false local grounded = false local idleAnimation = Instance.new("Animation") idleAnimation.AnimationId = "rbxassetid://317651678" local runningAnimation = Instance.new("Animation") runningAnimation.AnimationId = "rbxassetid://319211805" local R2 = Instance.new("Animation") R2.AnimationId = "rbxassetid://319228239" --local I2 = Instance.new("Animation") --I2.AnimationId = "rbxassetid://319228239" function playAnimation(parent) local AnimTrack = player.Character.Humanoid:LoadAnimation(parent) AnimTrack:Stop() wait(.1) AnimTrack:Play() end function onGround(speed) if grounded == false then grounded = true end if speed > 1 and player.PlayerGui.SwordPlaySystem.Stance.Value == ("Left") then if already_ran == false then already_ran = true playAnimation(runningAnimation) elseif speed > 1 and player.PlayerGui.SwordPlaySystem.Stance.Value == ("Right") then if already_ran == false then already_ran = true playAnimation(R2) end end else already_ran = false playAnimation(idleAnimation) end end end onSpawn() player.Character.Humanoid.Running:connect(onGround)
So. 1) What EXACTLY are you asking for? 2) Have you checked for any script that causes lag, or too many parts? 3) Have you tried using a anti-lag plugin such as Ro-Defender? 4) Is that the ENTIRE code? Is there a function at the start?