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

how would I use math.random to make a randomizer?

Asked by 5 years ago

Does anyone know how to make a randomizer?

Like, say for example, when a new server exists, a part can be either red, orange, or yellow.

Maybe have to where a script makes a NumberValue will change between 1 and 3. And when I figure that out I want to figure out how to make it like:

1if script.Parent.Value.Value=1 then
2    script.Parent.Transparency=1
3 
4if script.Parent.Value.Value=2 then
5    script.Parent.Transparency=0.5
6 
7if script.Parent.Value.Value=3 then
8    script.Parent.Transparency=0
9end

Please help me.

Spoiler Alert,

On part of the Roblox game Isolator, in one of the rooms has a computer that says either Left or Right. I want to make something similar to that.

If

1 answer

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

Math.random you can use different ways. One of those ways, is to generate a number through another number. But you might notice, if you use it more than once in the same game/server, it will keep generating the same number. So you can use math.randomseed to make the numbers generate more random each time. Now it should be different every time.

This would be a part touched event.

01math.randomseed(tick()) --Seeds the random number function by your local time.
02 
03debounce = false
04local number = (math.random(1,3))
05script.Parent.Touched:Connect(function()
06if debounce == false then
07if number == 1 then
08    script.Parent.Transparency=1
09 
10elseif number == 2 then
11    script.Parent.Transparency=0.5
12 
13elseif number == 3 then
14    script.Parent.Transparency=0
15end
16debounce = true
17wait (2) --Time you want before the next player can touch to change it
18debounce = false
19end
20end)

This would be a part clicked event

01math.randomseed(tick()) --Seeds the random number function by your local time.
02 
03local number = (math.random(1,3))
04debounce = false
05script.Parent.MouseClick:Connect(function()
06if debounce = false then
07if number == 1 then
08    script.Parent.Transparency=1
09 
10elseif number == 2 then
11    script.Parent.Transparency=0.5
12 
13elseif number == 3 then
14    script.Parent.Transparency=0
15end
16debounce = true
17wait(2) --Time you want before the next player can click to change it
18debounce = false
19end
20end)
Ad

Answer this question