How i use run animation in run script

i scripted run script but i tried run animation but doesnt work, anyways i used another method (jump to play animation) but i have some bugs.

Script :arrow_down: (Server script)

local anims = {
	run = "http://www.roblox.com/asset/?id=913376220",
	walk = "http://www.roblox.com/asset/?id=913402848",
}

local humanoid = script.Parent:FindFirstChild("Humanoid")
local animate = script.Animate

local oldAnimate = script.Parent:FindFirstChild("Animate")
oldAnimate:Destroy()

animate.Parent = script.Parent

humanoid:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	if humanoid.WalkSpeed < 17 then
		animate.run.RunAnim.AnimationId = anims.walk
		humanoid.JumpPower = 1
		humanoid.Jump = true
		wait()
		humanoid.JumpPower = 50
	elseif humanoid.WalkSpeed >= 17 then
		animate.run.RunAnim.AnimationId = anims.run
		humanoid.JumpPower = 1
		humanoid.Jump = true
		wait()
		humanoid.JumpPower = 50
	end
end)

if I didn’t make a mistake and understand what you want, it’s like this

local anims = {
run = “http://www.roblox.com/asset/?id=913376220”,
walk = “http://www.roblox.com/asset/?id=913402848”,
}

local humanoid = script.Parent:FindFirstChild(“Humanoid”)
local animate = script.Animate

local RunAnimation = Instance.new(‘Animation’)
RunAnimation.AnimationId = anims.run
RAnimation = humanoid:LoadAnimation(RunAnimation)

local WalkAnimation = Instance.new(‘Animation’)
WalkAnimation.AnimationId = anims.walk
WAnimation = humanoid:LoadAnimation(WalkAnimation)

humanoid:GetPropertyChangedSignal(“WalkSpeed”):Connect(function()
if humanoid.WalkSpeed < 17 then
WAnimation:Play()
RAnimation:Stop()
humanoid.JumpPower = 1
humanoid.Jump = true
wait()
humanoid.JumpPower = 50
elseif humanoid.WalkSpeed >= 17 then
RAnimation:Play()
WAnimation:Stop()
humanoid.JumpPower = 1
humanoid.Jump = true
wait()
humanoid.JumpPower = 50
end
end)

2 Likes

i will try this code! thanks for now

local anims = {
	run = "http://www.roblox.com/asset/?id=913376220",
	walk = "http://www.roblox.com/asset/?id=913402848",
}

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animate = script:WaitForChild("Animate")
animate.Parent = script.Parent
local oldAnimate = character:WaitForChild("Animate")
oldAnimate:Destroy()

humanoid.Running:Connect(function(speed)
	if speed < 17 then
		animate.run.RunAnim.AnimationId = anims.walk
		humanoid.JumpPower = 1
		humanoid.Jump = true
		task.wait()
		humanoid.JumpPower = 50
	elseif speed >= 17 then
		animate.run.RunAnim.AnimationId = anims.run
		humanoid.JumpPower = 1
		humanoid.Jump = true
		task.wait()
		humanoid.JumpPower = 50
	end
end)

Listen for the “Running” event to fire on the humanoid instance instead as it’s purposed for this task and I believe Humanoid:GetPropertyChangedSignal("WalkSpeed") doesn’t fire because it’s a physics related property.

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Running

If you run into any other issues then it’s likely related to the convoluted instance organisation.

1 Like

thanks for help but

LaureateCnepmoCTpeJl007

2d

if I didn’t make a mistake and understand what you want, it’s like this

local anims = {
run = “http://www.roblox.com/asset/?id=913376220”,
walk = “http://www.roblox.com/asset/?id=913402848”,
}

local humanoid = script.Parent:FindFirstChild(“Humanoid”)
local animate = script.Animate

local RunAnimation = Instance.new(‘Animation’)
RunAnimation.AnimationId = anims.run
RAnimation = humanoid:LoadAnimation(RunAnimation)

local WalkAnimation = Instance.new(‘Animation’)
WalkAnimation.AnimationId = anims.walk
WAnimation = humanoid:LoadAnimation(WalkAnimation)

humanoid:GetPropertyChangedSignal(“WalkSpeed”):Connect(function()
if humanoid.WalkSpeed < 17 then
WAnimation:Play()
RAnimation:Stop()
humanoid.JumpPower = 1
humanoid.Jump = true
wait()
humanoid.JumpPower = 50
elseif humanoid.WalkSpeed >= 17 then
RAnimation:Play()
WAnimation:Stop()
humanoid.JumpPower = 1
humanoid.Jump = true
wait()
humanoid.JumpPower = 50
end
end)

answered and worked

No problem, I just decided to offer a more specific solution (using .Running which already exists) instead of creating a custom event listener for the WalkSpeed property with the “GetPropertyChangedSignal()” instance method.