Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

[ANSWERED] How would I test for the TimePosition of audio in this script?

I'm trying to activate a lava block's script when the TimePosition is at 75 and 80 seconds, but nothing's happened at those times. Could I get a little help? Thank you in advance!

function scoop()
	script.Parent.BrickColor = BrickColor.new("Really Red")
	script.Parent.scooper:Play()
	if script.Parent.scooper.TimePosition == 75 then
		game.Workspace.Lava.Script.Disabled = false
	end
	if script.Parent.scooper.TimePosition == 80.00 then
		script.Parent.scooper:Stop()
		game.Workspace.Lava.Script.Disabled = true
	end
	wait(5)
	script.Parent.BrickColor = BrickColor.new("Lime Green")
end

script.Parent.ClickDetector.MouseClick:connect(scoop)

(Also, the button I'm clicking on doesn't change to the Really Red color once clicked if anyone wants to help me with that but that's not really important now!)

1 answer

✓ Accepted answer

The issue here is that Doubles (what TimePosition is) are not very precise.

Checking if TimePosition is exactly equal to a number is useless, but you also aren't waiting at all for it, so the if statements are being checked immediately!

function scoop()
    script.Parent.BrickColor = BrickColor.new("Really Red")
    script.Parent.scooper:Play()

    wait(75)
    while script.Parent.scooper.TimePosition < 75 do wait() end
    game.Workspace.Lava.Script.Disabled = false

    wait(5)
    while script.Parent.scooper.TimePosition < 80 do wait() end
    script.Parent.scooper:Stop()
    game.Workspace.Lava.Script.Disabled = true

    wait(5)
    script.Parent.BrickColor = BrickColor.new("Lime Green")
end

script.Parent.ClickDetector.MouseClick:connect(scoop)

1 comment

0

Thank you so much! It worked perfectly!

This discussion is preserved as it was. New answers, comments, and votes are closed.