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

Why this math.random value isnt working?

Asked by 6 years ago

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)
2
It's a range, not an inclusive list. math.random(6), or math.random(1,6) both do the same. WoolHat 53 — 6y
0
math.random(1,6) Astralyst 389 — 6y
0
i did this, but still the same number every time i use, its always 6 darkzerobits 92 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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!

0
thanks ^^ darkzerobits 92 — 6y
0
Btw it should be math.randomseed(os.time()) not tick(), other then that good answer plasma_node 343 — 6y
0
Ok, thanks for the feedback! Crazycat4360 115 — 6y
0
wouldn't make any difference unmiss 337 — 6y
Ad

Answer this question