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

Why this math.random value isnt working?

i dont know why this math.value isnt working, i want that when i click, will choose a random number between 1 and 6, but dont work


function onClicked()
	if script.Parent.Parent.Parent.Parent.stats.BornZone.Value == "None" then
	script.Parent.Parent.Parent.Parent.stats.BornZone.Value = math.random(1,2,3,4,5,6)
	
end 

script.Parent.MouseButton1Click:connect(onClicked)

3 comments

2

It's a range, not an inclusive list. math.random(6), or math.random(1,6) both do the same.

0

math.random(1,6)

0

i did this, but still the same number every time i use, its always 6

1 answer

✓ Accepted answer

Like @WoolHat said, math.random uses two numbers and then chooses one in between, but the math.random generator will always have a certain order unless you use math.randomseed. math.randomseed gives the generator a random 'seed' therefore, the number will always be different.

math.randomseed(tick())
function onClicked()
    if script.Parent.Parent.Parent.Parent.stats.BornZone.Value == "None" then
    script.Parent.Parent.Parent.Parent.stats.BornZone.Value = math.random(1,6)
end
script.Parent.MouseButton1Click:connect(onClicked)

Hope this helps!

4 comments

0

thanks ^^

0

Btw it should be math.randomseed(os.time()) not tick(), other then that good answer

0

Ok, thanks for the feedback!

0

wouldn't make any difference

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