Why does :GetPropertyChanged not fire? (is he stupid?)

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
1 Like

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

Yeah that’s what I ended up doing.

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