This is my first attempt on a map and timed game, but I'm not sure if this code will work, to change maps. I just started learning advanced scripting :3
All my maps are in Lightning, around 5 maps.
maps = {"Classic", "Large", "Medium", "Small"} --Name of the model, also known as the map time = math.random(300,600) script.Parent.TimeValue.Value = time players = game.Players:GetChildren() function ChooseMap() map = game.Lighting.maps[1,#maps]:Clone() --Clones a Random Map map.Parent = game.Workspace --Puts the map in Workspace end mapname = map.Name while players >= 4 do --If there are 4 or more players, then... ChooseMap() --Does the function for i,v,players in pairs do players:MoveTo(script.Parent.(mapname).PlayerSpawn.Position) --Teleports everyone to the PlayerSpawn sniper = math.random(players) --Selects a random player to become the Sniper sniper:MoveTo(script.Parent.(mapname).SniperSpawn.Position) --teleports the Sniper to the Sniper's Spawn repeat wait(1) script.Parent.TimeLeft.Value = time-1 until script.Parent.TimeLeft.Value == 0 end wait(15) script.Parent.(mapname):Destroy() wait(60) end
This should work. You had some pieces of code out of order, some parts that were extra, and some that needed just a slight adjustment. You did a great job of writing the first draft, the next thing you need to know is how to debug your own code and to double check thing against the wiki. Hope I helped, accept the answer and/or up vote if I did. Thanks!
local maps = {"Classic", "Large", "Medium", "Small"} --Name of the model, also known as the map local time = math.random(300,600) --local variable lookup is faster, therefore reducing lag. local script.Parent.TimeValue.Value = time --players is defined later function ChooseMap() map = game.Lighting.maps[math.random(#maps)]:Clone() --Clones a Random Map map.Parent = game.Workspace --Puts the map in Workspace end while wait(0) do local players = game.Players:GetChildren() if #players > 3 then --If there are more than 3 (4 or more) players, then… ChooseMap() --Chooses the map local sniper = math.random(#players) --selects a random player to assign to var 'sniper' players[sniper]:MoveTo(map.SniperSpawn.Position) --Choose sniper and send to sniper spawn. for i,v, in pairs(players) do --for each player do if v ~= sniper then --if player not sniper then v:MoveTo(map.PlayerSpawn.Position) --Players to player spawn end end repeat --countdown waitTime = wait(1) --record actual time waited when asked to wait for one second script.Parent.TimeLeft.Value = time-waitTime --subtracts the actual time waited. print(math.floor(time+.5) --this is what you should use to display time, if you do. until script.Parent.TimeLeft.Value <= 0 wait(15) map:Destroy() --destroy the cloned map time = math.random(300,600) --resets the random time end end