So I'm really new to scripting and am trying to make a simple minigame to kickstart me. I have 2 maps, and when I keep out the script for the 2nd map it works fine. However, when I put in the script for the second map, the entire script breaks and I don't know what the problem is. Hopefully this isn't too long for help.
m = Instance.new('Message', workspace) h = Instance.new('Hint', workspace) local sword = game.Lighting.ClassicSword:Clone() num = math.random(1,2) map = game.Lighting.SF:Clone() map2 = game.Lighting.Obby:Clone() players = game.Players:GetChildren() while true do wait(1) for i = 5, 1, -1 do h.Text = "Choosing map in: "..i wait(1) end h:Remove() if num == 1 then -- if the first map is picked h = Instance.new('Hint', workspace) m.Text = "Map Number "..num.." Has Been Chosen!" wait(3) m.Text = "Sword Fight, Created by EternallySpeedy" wait(3) m.Text = "Be the last one alive!" m:Remove() wait(3) h.Text = "Loading Map..." wait(5) map.Parent = game.Workspace -- loading the map map.Name = "Map" map:MakeJoints() h.Text = "Teleporting Players..." wait(3) h:Remove() target = Vector3.new(48.7, 0.5, 32.455) -- teleporting the players for i, v in pairs(game.Players:GetChildren()) do v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0)) m = Instance.new('Message', workspace) h = Instance.new('Hint', workspace) m.Text = "3" wait(1) m.Text = "2" wait(1) m.Text = "1" wait(1) m.Text = "Begin!" wait(1) m:Remove() sword:Clone().Parent = game.Players.LocalPlayer.Backpack end for i = 60, 1, -1 do h.Text = "Round ends in: "..i -- countdown until the round is over wait(1) end h.Text = "The round is over." wait(1) map:Remove() wait(5) end for i = 15, 1, -1 do -- countdown until the loop restarts h.Text = "Intermission: "..i wait(1) end m:Remove() h:Remove() m = Instance.new('Message', workspace) h = Instance.new('Hint', workspace) end if num == 2 then -- If the second map is picked h = Instance.new('Hint', workspace) m.Text = "Map Number "..num.." Has Been Chosen!" wait(3) m.Text = "Obby 1, Created by EternallySpeedy" wait(3) m.Text = "Be the first to finish!" m:Remove() wait(3) h.Text = "Loading Map..." wait(5) map2.Parent = game.Workspace -- loading the map map2.Name = "Map2" map2:MakeJoints() h.Text = "Teleporting Players..." wait(3) target = Vector3.new(48.7, 0.5, 10) -- teleporting players for i, v in pairs(game.Players:GetChildren()) do v.Character.Torso.CFrame = CFrame.new(target + Vector3.new(0, i * 5, 0)) m = Instance.new('Message', workspace) h = Instance.new('Hint', workspace) m.Text = "3" wait(1) m.Text = "2" wait(1) m.Text = "1" wait(1) m.Text = "Begin!" wait(1) m:Remove() for i = 60, 1, -1 do -- countdown until the round is over h.Text = "Round ends in: "..i wait(1) end h.Text = "The round is over." wait(1) map2:Remove() wait(5) end for i = 15, 1, -1 do h.Text = "Intermission: "..i -- countdown until the loop restarts wait(1) end m:Remove() h:Remove() m = Instance.new('Message', workspace) h = Instance.new('Hint', workspace) end
I think that its because you put your if statement that checks if the num == 2 is in a if statement the checks if the num == 1. Try Backspaceing the second If statement out of the first If statement
Looking at the full script, there seem to be two main problems. First and foremost, you didn't add the second map script inside of the while loop. Therefore the script would only pick the first map if everything else worked. But I said there was a second problem: the random number for the map is generated outside of the while loop, so if it generates 2 as it stands now, it will continue looping indefinitely without ever picking a map.