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

How do I make my four corners game have a different color selected each time?

Asked by 7 years ago

I made a four corners game but everything I do to try to make the outcome be random each time doesn't work. It keeps doing the same one every time. Here's my attempt so far:

value = game.Workspace.changedvalue.Value
blue = game.Workspace.Blue
red = game.Workspace.Red
yellow = game.Workspace.Yellow
green = game.Workspace.Green
barrier = game.Workspace.barrier.CanCollide
barrier1 = game.Workspace.barrier1.CanCollide
barrier2 = game.Workspace.barrier2.CanCollide

while true do
    wait(math.random(5,10))
    if value == 1 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        blue.CanCollide = false
        blue.Transparency = 0.5
        wait(3)
        blue.CanCollide = true
        blue.Transparency = 0
    elseif value == 2 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        red.CanCollide = false
        red.Transparency = 0
        wait(3)
        red.CanCollide = true
        red.Transparency = 0
    elseif value == 3 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        yellow.CanCollide = false
        yellow.Transparency = 0.5
        wait(3)
        yellow.CanCollide = true
        yellow.Transparency = 0
    elseif value == 4 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        green.CanCollide = false
        green.Transparency = 0.5
        wait(3)
        green.CanCollide = true
        green.Transparency = 0
    else
        print("Mission failed, we'll get em' next time")
    end
end

(the value I put in randomizes every half a second

2 answers

Log in to vote
0
Answered by 7 years ago

You are looking for a function called math.random

Example:

math.randomseed(os.time());

local Colors = { workspace.Yellow, workspace.Red, workspace.Green, workspace.Blue;
};

function RandomColor()
    return Colors[math.random(0, #Colors)];
end
0
i already used it in the different script which is why i put in parenthesis "the value is randomized every half second" Quackshire 17 — 7y
0
He typoed, he meant math.randomseed() Thundermaker300 554 — 7y
Ad
Log in to vote
0
Answered by
Rawblocky 217 Moderation Voter
7 years ago

The value isn't getting refreshed, so it will stick with the same value on the start of the game. Here's an edited script:

value = game.Workspace.changedvalue.Value
blue = game.Workspace.Blue
red = game.Workspace.Red
yellow = game.Workspace.Yellow
green = game.Workspace.Green
barrier = game.Workspace.barrier.CanCollide
barrier1 = game.Workspace.barrier1.CanCollide
barrier2 = game.Workspace.barrier2.CanCollide

while true do
    wait(math.random(5,10)changedvalue.Value
    if value == 1 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        blue.CanCollide = false
        blue.Transparency = 0.5
        wait(3)
        blue.CanCollide = true
        blue.Transparency = 0
    elseif value == 2 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        red.CanCollide = false
        red.Transparency = 0
        wait(3)
        red.CanCollide = true
        red.Transparency = 0
    elseif value == 3 then
        barrier = true
        barrier1 = true
        barrier2 = true
        wait(1)
        yellow.CanCollide = false
        yellow.Transparency = 0.5
        wait(3)
        yellow.CanCollide = true
        yellow.Transparency = 0
    elseif value == 4 then
        barrier = true
        barrier1 = true
        barrier2 = true

        wait(1)
        green.CanCollide = false
        green.Transparency = 0.5
        wait(3)
        green.CanCollide = true
        green.Transparency = 0
    else
        print("Mission failed, we'll get em' next time")
    end
end

Answer this question