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)
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)
You see your typing hum.WalkSpeed.Changed thats not how it works. Let me explain 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
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)
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)