Adding a animation when over a certain speed not working

Hello. I’m making a speedster game, and for some reason my animation won’t activate, when the player is going over a certain speed.

Here is the script:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local animation = script.Animation
		local loadAnim = hum:LoadAnimation(animation)

		hum.WalkSpeed.Changed:Connect(function(newSpeed)
			if newSpeed >= 17 then
				loadAnim:Play()
			else
				loadAnim:Stop()
			end
		end)
	end)
end)

Help is appreciated.

2 Likes

Try this out:

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local animation = script.Animation
		local loadAnim = hum:LoadAnimation(animation)

		hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function(newSpeed)
			if newSpeed >= 17 then
				loadAnim:Play()
			else
				loadAnim:Stop()
			end
		end)
	end)
end)
2 Likes

Hey so the problem is here:

hum.WalkSpeed.Changed:Connect(function(newSpeed)

You see your typing hum.WalkSpeed.Changed thats not how it works. Let me explain image
WalkSpeed is a property of humanoid. Using .Changed on a property results in an error, and thats what you are doing causing an error remove WalkSpeed and leave normal A.K.A

hum.Changed:Connect(function(newSpeed)

still dosen’t work and sorry about me not replying earlier i weren’t on my pc

I might be totally wrong but maybe try this?

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local animation = script.Animation
                local Animator = hum:WaitForChild("Animator")
                local loadAnim = Animator:LoadAnimation(animation)
                
		hum:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
			if hum.WalkSpeed >= 17 then
				loadAnim:Play()
			else
				loadAnim:Stop()
			end
		end)
	end)
end)
1 Like

still dosen’t work


Question: why do you need this script on server side?

it dosen’t need to be server side

i just want to make a clean transition when starting to run instead of a run anim starting and it just starts half way through the anim it looks dumb

Well then why aren’t you playing the animation in a local script? Try doing it on a local script maybe

This wouldn’t work on server since walkspeed doesn’t replicate you’d have to do it on local instead.

local __PLAYER = game:GetService("Players").LocalPlayer
local __CHARACTER = __PLAYER.Character or script.Parent
local __ANIMATION: Animation? = script:FindFirstChild("ANIMATOINHERE")
local __HUMANOID = __CHARACTER:FindFirstChildOfClass("Humanoid")
local __ANIMATOR = __HUMANOID:FindFirstChildOfClass("Animator")
local __RUNANIM = __ANIMATOR:LoadAnimation(__ANIMATION)


__HUMANOID:GetPropertyChangedSignal("WalkSpeed"):Connect(function()
	if __HUMANOID.WalkSpeed >= 17 then
		__RUNANIM:Play()
	else
		__RUNANIM:Stop()
	end
end)
1 Like

dosen’t work


How come? It worked for me… Is the script in startercharacter?

i realised you had put FindFirstChild instead of WaitForChild Here:

local __ANIMATION: Animation? = script:FindFirstChild(“ANIMATOINHERE”)

And i had forgot to put animation id.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.