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

Random Map changer problem?

Asked by 10 years ago

I'm trying to make a random map chooser and it picks one map but then after it says "changing mapz" the message goes away and the map stays there and I want it to keep changing randomly.

local ran = math.random(1,5)
local msg = Instance.new("Message")
msg.Parent = game.Workspace

while true do
if ran == 1 then
    game.Lighting.field1:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: City"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field1:remove()
elseif ran == 2 then
    game.Lighting.field2:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Original"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field2:remove()
elseif ran == 3 then
    game.Lighting.field3:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: ClockWork Village"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field3:remove()
elseif ran == 4 then
    game.Lighting.field4:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Mario Bros."
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field4:remove()
elseif ran == 5 then
    game.Lighting.field5:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Mount Doom"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field5:remove()
end
end

3 answers

Log in to vote
1
Answered by 10 years ago

The variable ranis a random value set at the beginning of the script, meaning it NEVER changes from the first random result. Try putting this within the end of the while loop:

ran = math.random(1,5)
Ad
Log in to vote
1
Answered by 10 years ago

So do I do

local ran = math.random(1,5)
local msg = Instance.new("Message")
msg.Parent = game.Workspace

while true do
if ran == 1 then
    game.Lighting.field1:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: City"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field1:remove()
elseif ran == 2 then
    game.Lighting.field2:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Original"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field2:remove()
elseif ran == 3 then
    game.Lighting.field3:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: ClockWork Village"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field3:remove()
elseif ran == 4 then
    game.Lighting.field4:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Mario Bros."
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field4:remove()
elseif ran == 5 then
    game.Lighting.field5:clone().Parent = game.Workspace
    game.StarterGui.CurrentMap.TextLabel.Text = "Current Map: Mount Doom"
    wait(30)
    msg.Text = "Changing mapz"
    wait(2)
    msg:remove()
    wait(2)
    game.Workspace.field5:remove()
end
ran = math.random(1,5)
end

Log in to vote
0
Answered by
Redbullusa 1580 Moderation Voter
10 years ago

CamKiller10 meant the ran variable should be placed right...

local msg = Instance.new("Message")
msg.Parent = game.Workspace

while true do
local ran = math.random(1,5)                -- Here.
if ran == 1 then

Answer this question