So I have my character and I animated a walking script for it. But when I walk this happens: robloxapp-20210628-1147111.wmv (1.7 MB)
Here is the code:
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)
Humanoid.Running:Connect(function(speed)
if not animationTrack.IsPlaying then
animationTrack:Play()
end
if Humanoid.Running == false then
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end
end)
The script is inside of StarterCharacterScripts and is local.
Can you try this code, I think the animation should function properly now:
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)
Humanoid.Running:Connect(function(speed)
if speed>0.1 then
if not animationTrack.IsPlaying then
animationTrack:Play()
end
else
if animationTrack.IsPlaying then
animationTrack:Stop()
end
end)
being a connection or a number, it will never give false, try this and place the animation as a loop
local character = script.Parent
local Humanoid = character:WaitForChild("Humanoid")
local animation = script:WaitForChild("Animation")
local animationTrack = Humanoid.Animator:LoadAnimation(animation)
Humanoid.Running:Connect(function(speed)
if not animationTrack.IsPlaying then
animationTrack:Play()
elseif speed == 0 and animationTrack.IsPlaying then
animationTrack:Stop()
end
end)
Also this says the API Reference
While running Humanoids cover, on average, their Humanoid.WalkSpeed in studs per second.
When the Humanoid stops running this event will fire with a speed of 0.