Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 8 years ago
Edited 8 years ago

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

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
8 years ago

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)
0
Thank you so much! It worked perfectly! Marioluigi35 7 — 8y
Ad

Answer this question