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 4 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:

if script.Parent.Value.Value=1 then
    script.Parent.Transparency=1

if script.Parent.Value.Value=2 then
    script.Parent.Transparency=0.5

if script.Parent.Value.Value=3 then
    script.Parent.Transparency=0
end

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 4 years ago
Edited 4 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.

math.randomseed(tick()) --Seeds the random number function by your local time.

debounce = false
local number = (math.random(1,3))
script.Parent.Touched:Connect(function()
if debounce == false then
if number == 1 then
    script.Parent.Transparency=1

elseif number == 2 then
    script.Parent.Transparency=0.5

elseif number == 3 then
    script.Parent.Transparency=0
end
debounce = true
wait (2) --Time you want before the next player can touch to change it
debounce = false
end
end)

This would be a part clicked event

math.randomseed(tick()) --Seeds the random number function by your local time.

local number = (math.random(1,3))
debounce = false
script.Parent.MouseClick:Connect(function()
if debounce = false then
if number == 1 then
    script.Parent.Transparency=1

elseif number == 2 then
    script.Parent.Transparency=0.5

elseif number == 3 then
    script.Parent.Transparency=0
end
debounce = true
wait(2) --Time you want before the next player can click to change it
debounce = false
end
end)
Ad

Answer this question