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