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

How would I fix this round script? It won't even say anything in output.

Asked by 6 years ago

I'm making a game that has rounds where it loads in the new map, teleports all the players there, teleports them back to the lobby, then deletes the map. In workspace I have a folder called "CurrentMap" and a string value called "ChosenMap" inside the script. All the maps are in lighting until they're supposed to be moved to workspace.

Here's the video I was using for help - https://www.youtube.com/watch?v=VpMDfiR6MwM&t=157s

local players = game.Players:GetChildren()
local maps = game.Lighting.Maps:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = script:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn")
local choices = {}


--Choose a random map

function chooseMap()
for i = 1,#maps do
    if maps [i]:isA("Model") then
        table.insert(choices,maps[i])
    end
end
local picked = math.random(1,#maps)
chosenmap.Value = choices[picked].Name

--Loading in the maps

function loadMap()
    local map = game.Lighting.Maps.FindFirstChild(chosenmap.Value)
    map:Clone().Parent = currentmap
end


--Deleting the maps
function deleteMap()
    for i,v in pairs(currentmap:GetChildren())do
        if v:isA("Model")then
            v:Destroy()
        end
    end
end


--Teleporting the players

function teleportPlayers()
    for i,v in pairs (players)do
        v.Character.HumanoidRootPart.CFrame =
            currentmap:FindFirstChild(chosenmap.Value).Spawn.CFrame
        *CFrame.new(math.random(5,10),0,math.random(5,10))
    end
end

--Teleporting Players Back

function teleportBack()
    for i,v in pairs(players)do
        v.Character.HumanoidRootPart.CFrame =
                spawner.SpawnLocation.CFrame*CFrame.new(math.random(5,10),0,math.random(5,10))
    end
end


--The whole cycle
while true do
    wait(3)
    chooseMap()
    loadMap()
    wait(1)
    teleportPlayers()
    wait(10)
    deleteMap()
    teleportBack()
end



If anyone could fix this for me, that would be great! My friend and I are new to scripting so we're still using lots of guides. So if there's anything else you think we should check out to improve our skills, that would be much appreciated! Thanks.

2
On line 23, you did ".FindFirstChild", It's supposed to be ":FindFirstChild". Mayk728 855 — 6y
0
yea you did Rawblocky 217 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

On that Youtube video you linked, the first comment has the entire script posted. :) Also, I wouldn't use Lighting to store your Maps. You can store them in a folder in ServerStorage. AlvinBloxx has a great six-part Youtube series explaining how to set up a rounds system that you may find helpful.

Script:
local players = game.Players:GetChildren()
local maps = game.Lighting:GetChildren()
local currentmap = game.Workspace:WaitForChild("CurrentMap")
local chosenmap = Script.Workspace:WaitForChild("ChosenMap")
local spawner = game.Workspace:WaitForChild("Spawn") -- Change "Spawn" to your spawn name
local choices = {}

--Choose a random map

function chooseMap()
  for I=1,#maps do
    if maps[i]:isA("Model") then
        table.insert(choices,maps[i]}
      end
   end
    local picked = math.random(1,#maps)
     chosenmap.Value = choices[picked].Name
   end

--Load the map
function loadMap()
   local map = gam.Lighting.Maps:FindFirstChild(chosenmap.Value)
   map:Clone().Parent = currentmap
 end

--Delete the map
function deleteMap()
  for i,v in pairs(currentmap:GetChildren()) do
    if v:isA("Model") then
       v:Destroy()
     end
   end
end

--Teleport all the players
function teleportPlayers()
  for i,v in pairs(players) do
    v.Character.HumanoidRootPart.CFrame = currentmap:FindFirstChild(chosenmap.Value).Spawn * CFrame.new(math.random(5,10),0,math.random(5,10))
  end
end

 --Teleport back the players
function teleportBack()
  for i,v in pairs(players) do
    v.Character.HumaniodRootPart.CFrame =
    spawner.SpawnLocation.CFrame *
    CFrame.new(math.random(5,10),0,math.random(5,10))
  end
end

while true do
 wait(3)
 chooseMap()
 loadMap()
 wait(1)
 teleportPlayers()
 wait(10)
 deleteMap()
 teleportBack()
end?
0
For some reason it still doesn't work even though it says no errors or warnings. I made a video on it here -> https://www.youtube.com/watch?v=gkkkik3yiZo&t=0s louieball 5 — 6y
Ad

Answer this question