Help with Sound.TimePosition

Hello, I’m trying to make a chart editor but the script can’t create notes because TimePosition isn’t working, when I tried printing TimePosition it just printed 0 when it started playing

Code:

Song:Play()
Song:GetPropertyChangedSignal("TimePosition"):Connect(function()
	print(Song.TimePosition)
	if Song.TimePosition == game.ReplicatedStorage["Gloo Gloo"][NoteNumber].Value then
		local RandomButton = math.random(2, #GameFrame:GetChildren())
		CreateNote(GameFrame:GetChildren()[RandomButton], 0.5)
		NoteNumber = NoteNumber + 1
	end
end)

i think it’s due to the fact time positions have decimals and it will count decimals, since it is in the local script it will print even faster which can cause the whole script to lag like crazy, you should add some dividers i think which distances individual print positions like adding “x” by 1 every print and if it hits 50 it will reset then print it

this is probably to avoid lagging and killing the server’s output thingy

if math.floor(Song.TimePosition + 0.5) == game.ReplicatedStorage["Gloo Gloo"][NoteNumber].Value then

Song.TimePosition returns double not intvalue so we need to floor, atleast i guess u do.

by the way i almost forgot you should use >= instead because it can sometimes skip a slight bit of numbers which are very common

roblox does not let you connect events to timeposition for some reason
so you can use heartbeat instead :man_shrugging:

local Song = script.Parent
Song:Play()

game:GetService("RunService").Heartbeat:Connect(function()
	if Song.Playing == true then
		print(Song.TimePosition)
	end
end)

you can math.floor if u dont want decimals too, and you can disconnect if the song stopped playing if u dont want it to keep on printing

If I use math.floor it won’t sync with the music because i need the decimals
image

Woah, didnt know u were using exact values. Respect!

Try using RenderStepped which is more efficient.