So, I have no idea what the error is this time.. D: So here it is:
RoundStart = game.Workspace.RoundStart Room1 = game.ServerStorage.Room1 Room2 = game.ServerStorage.Room2 Room3 = game.ServerStorage.Room3 Room4 = game.ServerStorage.Room4 Room5 = game.ServerStorage.Room5 function NewMap() if RoundStart.Value == true then RandomRoom = (math.random(1,5)) if RandomRoom == 1 then local Map1 = Room1:Clone() Map1.Parent = game.Workspace end if RandomRoom == 2 then local Map2 = Room2:Clone() Map2.Parent = game.Workspace end if RandomRoom == 3 then local Map3 = Room3:Clone() Map3.Parent = game.Workspace end if RandomRoom == 4 then local Map4 = Room4:Clone() Map4.Parent = game.Workspace end if RandomRoom == 5 then local Map5 = Room5:Clone() Map5.Parent = game.Workspace end end end RoundStart.Value.Changed:connect(NewMap)
Please help?
I recommend using lists/tables when dealing with multiple objects:
RoundStart = game.Workspace.RoundStart --Initialize Rooms list numRooms = 5 Rooms = {} for i = 1, numRooms do Rooms[i] = game.ServerStorage["Room" .. i] end function NewMap() if RoundStart.Value then local randomRoom = math.random(1, 5) local map = Rooms[randomRoom]:Clone() map.Parent = workspace end end RoundStart.Value.Changed:connect(NewMap)
As you can see, using a list makes the NewMap function considerably smaller.
You might want to add RoundStart.Value = false
somewhere in the NewMap function (within the 'if RoundStart.Value then` block).
You need to do this because of this example.
local num = 0 --Variable --What you are doing is this test = 0 --This would mean that the variable test will be changed to 0. But in order to do this --"test" will need to be an already existing variable. --To let the script know you are making a new variable, put local behind it. num = 1 --This will work since num was created on line 1.
Is the the RoundStart value being changed? Instead of using a value, call the function in the script.
function startround() print("Starting round!") end startround() --Calling the function right here in the script!
Here is the perfected script, that may need some fixing. You can fix the rest.
function NewMap() local RandomRoom = game:GetService("ServerStorage"):FindFirstChild("Room"..math.random(1,5)) if RandomRoom then RandomRoom:clone().Parent = workspace end end end
Hope this helps!