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

Math.random always chooses 0?

Asked by
bloxxyz 274 Moderation Voter
10 years ago

This is my script, it always chooses "0", meaning the door's transparency will remain 0. I've tested it many times and it just doesn't seem to ever open the door. I understand random can sometimes repeat but, this is ridiculous. Any help? Do you see any errors I have skipped over in the last hour? Thank you.

sp=script.Parent

sp.ClickDetector.MouseClick:connect(function()
math.randomseed(tick())
sp.Transparency=math.random(0,1)
wait(3)
    if sp.Transparency==1 then
    game.Workspace.givecandy.Value = true
        wait(5)
            if sp.Transparency==1 then
            sp.Transparency = 0
            game.Workspace.givecandy.Value = false
            end
else
    print("not awake")
            end
end)

Again, no errors are shown in output, but if you see any I may have missed anyway please tell me. Or perhaps, I wrote the script wrong? Thank you again..

1 answer

Log in to vote
1
Answered by
Relatch 550 Moderation Voter
10 years ago
sp = script.Parent

sp.ClickDetector.MouseClick:connect(function()
    math.randomseed(tick())
    sp.Transparency = math.random(0, 1)
    wait(3)
    if sp.Transparency == 1 then
        game.Workspace.givecandy.Value = true
        wait(5)
        sp.Transparency = 0
        game.Workspace.givecandy.Value = false
    else
        print("Not Awake")
    end
end)

I'm pretty sure it's because you checked again if the Transparency equals 1. Since your script is still running after checking the first time that it's 1, you don't need to check again.

Try this.

0
thanks, I see what I did wrong :) bloxxyz 274 — 10y
0
No problem, thanks for the thumbs up. Relatch 550 — 10y
Ad

Answer this question