Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Alternating between walking animations?

Asked by
Chronomad 180
8 years ago

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)

1 answer

Log in to vote
0
Answered by 8 years ago

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?

0
In line 60 , do you see how it says if speed = 1 and player.playergui.SwordPlaySystem.Stance.Value == left? It plays an animation. However if you look at lines 65 - 68 , It's supposed to play a different animation when the value = ("Right"). That isn't happening. Chronomad 180 — 8y
0
Also, I use Ro - Defender, I'm not having any problems with lag. There is nothing creating any parts or instances of any kind endlessly, This is the ENTIRE code. It is inside of starterplayerscripts Chronomad 180 — 8y
0
Okay. If you contact my friend lukeb50, he can hook you up with something TheHospitalDev 1134 — 8y
Ad

Answer this question