Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

I'm making a sprint script (again) and It's animations aren't working properly. Can anyone help?

Here's the script

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local Animation = script.Parent:WaitForChild("Anim")
local Anim = Animation.AnimationId
local Original = Animate.walk.WalkAnim.AnimationId
local Running = script.Parent:WaitForChild("Running")

Running.Changed:Connect(function()
	
	print("Doing Stuff")
	
	if Humanoid.MoveDirection.Magnitude > 0 and Running.Value == true then
		
		Animate.walk.WalkAnim.AnimationId = Animation.AnimationId
		print("New Anim")
		
	else
		
		Animate.walk.WalkAnim.AnimationId = Original
		print("Old Anim")
		
	end
	
end)

The problem is that the animations aren't loading correctly, if you want to play the sprint animation, You can't do it while walking, You have to press shift before you start walking. If you want to stop the animation, you have to stop walking.

I've tried multiple scripts to do this.. But the problem isalways the same, The animations have trouble playing.

5 comments

0

Make use of Humanoid:LoadAnimation() and UserInputService for inputs.

0

why not write animation:stopped() change the id then animation:play again? u should try that.

0

If I make it play, It will not stop, will it?

0

i mean like every time ur gonna change the animation set the default one stop then change id then let new one play

0

How can I sop the default animation if I don't have the Loaded animation variable?

2 answers

You can change the Run animation of the character and the Walk animation if you want by going into the characters through a script and changing its animation settings.

local plr = game.Players.LocalPlayer
local char  = plr.Character
local Anims = char.Animate
local RunAnim = Anims.run.RunAnim

RunAnim.AnimationId = "http://www.roblox.com/asset/?id=YOURID"

if you want to change it permanently you can add this script to StarterCharacterScripts and change the animation so anytime that the player runs its animation should be changed already and you wont have to do it everytime they press shift, and roblox automatically decides when to play the run anim for you.

8 comments

0

The thing is, the character is r6. And there's no RunAnim for R6 O_o

0

@ZIRFAL3 im sure there is a RunAnim for R6 i converted my studio to R6 and went into the explorer and was able to find it.

0

Yes, but to but the r6 run animation is just the walk animation sped up

0

And I’m pretty sure it is not even used

0

no I believe it is used, you can test it by setting your character speed to about 30 and go into the character and deleting the id for the run animation, and if the animation stops you’ll know it’s being used

0

let me check..

0

no.. it didn't work..

0

if thats the case then instead of changing the RunAnim, change the WalkAnim?

I solved it! All I had to do was mae it so that the animation is loaded, played and immediatelly stopped, and let the animate script do the rest.

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local Animation = script.Parent.Anim
local Anim = Animation.AnimationId
local OriginalAnim = Animate.walk.WalkAnim
local Original = Animate.walk.WalkAnim.AnimationId
local Running = script.Parent:WaitForChild("Running")

Running.Changed:Connect(function()
	
	print("Doing Stuff")
	
	if Humanoid.MoveDirection.Magnitude > 0 and Running.Value == true then
		
		Animate.walk.WalkAnim.AnimationId = Animation.AnimationId
		local Test2 = Humanoid:LoadAnimation(Animation)
		print("New Anim")
		
		if Humanoid.MoveDirection.Magnitude > 0 then
			
			Test2:Play()
			Test2:Destroy()
			
		end
		
	else
		
		Animate.walk.WalkAnim.AnimationId = Original
		local Test = Humanoid:LoadAnimation(OriginalAnim)
		print("Old Anim")
		
		if Humanoid.MoveDirection.Magnitude > 0 then

			Test:Play()
			Test:Destroy()

		end
		
	end
	
end)

Thanks to everyone who tried helping, even though You did not solve it, I really appreciate it!

This discussion is preserved as it was. New answers, comments, and votes are closed.