-
What do you want to achieve? I want to play an animation (ID 5341398970) whenever my custom character walks.
-
What is the issue? The character’s animations do not appear to play, but AnimationTrack.IsPlaying is true.
-
What solutions have you tried so far? I have debugged a lot of different parts of my code as to see if I could fix this myself, along with a good amount of googling.
Here is my code. It is located in game.StarterPlayer.StarterCharacterScripts
.
-- Helperbot3 <3 --
-- Load character
local UIService = game:GetService("UserInputService")
repeat wait() until script.Parent.Humanoid
-- Create animations
local animWalk = Instance.new("Animation")
animWalk.AnimationId = "http://www.roblox.com/asset/?id=5341398970"
animWalk.Name = "Walk"
-- Prevent default animations
if(script.Parent:FindFirstChild("Animate"))then local i = script.Parent:FindFirstChild("Animate")i:Destroy()end
script.Parent.ChildAdded:Connect(function (child)if(child.Name == "Animate")then child:Destroy() end end)
-- Load animations
local hmnd = script.Parent.Humanoid
local trackWalk = hmnd:LoadAnimation(animWalk)
trackWalk.Looped = true
-- Other loading
local isWalking = false
function walkUpdate(bool)
local function fireChange(bool)
if(bool)then
print("start")
trackWalk:Play()
else
print("stop")
trackWalk:Stop()
end
end
if(bool ~= isWalking)then
isWalking = bool
fireChange(bool)
end
end
-- Code
hmnd.Running:Connect(function (speed)
if(speed >= 1)then
walkUpdate(true)
else
walkUpdate(false)
end
end)
spawn(function ()
while(true)do
if(trackWalk.IsPlaying)then
print("Playing!")
else
print("Not playing!")
end
wait(1)
end
end)
This script will output “start” when it believes the character started walking.
This script will output “stop” when it believes the character stopped walking.
Both above work flawlessly on both PC and Xbox. (Not tested on other devices.)
This script will output “Playing!” every second when AnimationTrack.IsPlaying is true, but if AnimationTrack.IsPlaying is false, it outputs “Not Playing!”
I would simply like my animation track to play (and work) when my character walks. Attached is my world: world.rbxl (99.8 KB)
READ ME!
The Weld script also moves the StarterCharacter model to the proper place. This is not an error caused by this extra script.