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

Math.random always chooses 0?

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

✓ Accepted answer
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.

2 comments

0

thanks, I see what I did wrong :)

0

No problem, thanks for the thumbs up.

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