I wrote a function that calls a function when an animationTrack loads
:GetPropertyChanged signal doesn’t fire for whatever reason.
local function ObserveAnimationTrackLoaded(track : AnimationTrack, callback : ()->()) : ()->()
print(`first length: {track.Length}`)
if track.Length ~= 0 then
callback()
return
end
local conn; conn = track:GetPropertyChangedSignal("Length"):Connect(function()
print(track.Length)
if track.Length ~= 0 then
callback()
conn:Disconnect()
return
end
end)
return function()
conn:Disconnect()
end
end
The Length property updates internally, so GetPropertyChangedSignal doesn’t fire for it. You have to use polling instead
local function ObserveAnimationTrackLoaded(track : AnimationTrack, callback : ()->())
if track.Length > 0 then callback() return end
task.spawn(function()
while track.Length == 0 do -- Poll until length loads
task.wait()
end
callback()
end)
end