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

How to make a random map and team generator?

Asked by 10 years ago
maps = game.ServerStorage.Maps:GetChildren()
map = maps[math.random(1, #maps)]
map:Clone().Parent = game.Workspace

for _,player in pairs(game.Players:GetPlayers()) do
    if player.Character then
        spawns = map.Spawns:GetChildren()
        player.Character:MoveTo(spawns[math.random(1, #spawns)].Position)
    end
end

I'm trying to make a sword fighting game, and I have players spawn in the lobby and I need it to choose a map and tp the players to the spawns. There are 2 teams, red and blue. What can I add or what do I need to get this to work?

2 answers

Log in to vote
2
Answered by 10 years ago

Okay so what you have laid out is spawning players on a random map. Maybe make an intermission period. This will be really basic.


while true do wait(30)--intermission maps = game.ServerStorage.Maps:GetChildren() map = maps[math.random(1, #maps)] map:Clone().Parent = game.Workspace for _,player in pairs(game.Players:GetPlayers()) do if player.Character then spawns = map.Spawns:GetChildren() player.Character:MoveTo(spawns[math.random(1, #spawns)].Position) end end wait(300) for i,player in pairs(game.Players:GetPlayers()) do if player.Character then player.Character.Head:remove() end end end

that is a basic game script but you mentioned teams correct?

while true do
    wait(30)--intermission
    maps = game.ServerStorage.Maps:GetChildren()
    map = maps[math.random(1, #maps)]
    map:Clone().Parent = game.Workspace
    blue = 0
    red = 0
    local teamplay = game.Players.GetChildren()
    for i = 1,game.Players.NumPlayers do
        local ran = math.random(1,game.Players.NumPlayers)
        if blue == red then -- if they are the same it is randomely generated
            br = math.random(1,2)
            if br == 1 then
                teamplay[ran].TeamColor = BrickColor.new("Bright blue")
            elseif br == 2 then
                teamplay[ran].TeamColor = BrickColor.new("Bright red")
            end
        elseif red >= blue then
            teamplay[ran].TeamColor = BrickColor.new("Bright red")
        elseif blue >= red then
            teamplay[ran].TeamColor = BrickColor.new("Bright blue")
        end
    end
    for _,player in pairs(game.Players:GetPlayers()) do
        if player.Character then
               spawns = map.Spawns:GetChildren()
         player.Character:MoveTo(spawns[math.random(1, #spawns)].Position)
       end
    end
    wait(300)-- five minutes
    for i,player in pairs(game.Players:GetPlayers()) do
        if player.Character then
            player.Character.Head:remove()
            player.TeamColor = BrickColor.new("White")
        end
    end
end

Just create 3 teams. One Bright blue, One Bright red, and another White. Spawns are still random but if you want to create seperate spawns, I'm sure you can do it (;

0
What would be white, lobby?? NinjoOnline 1146 — 10y
0
With line 30, I can change it to600 so its 10 mins per round?? I want it to be on a GUI countdown,will that be possible?? NinjoOnline 1146 — 10y
0
And at the top with intermission, I have already a count down in GUI, and set it to change a BoolValue to True once the countdown has finished. Can I just do if game.Workspace.BoolValue.Value = true then, will that work?? NinjoOnline 1146 — 10y
0
Do the spawns in the map have to be spawnlocations or can they just be blocks? NinjoOnline 1146 — 10y
View all comments (3 more)
0
It didnt work, what do I need to add to it, what should the maps be called, what should the spawns be called, etc tec NinjoOnline 1146 — 10y
0
I have fixed it, and the maps load, but you dont tp to the teams. What do I have to add?? NinjoOnline 1146 — 10y
0
Do you have a team service with teams that are {"Bright blue","Bright red","White"}? and yes White would be intermission. The question about the intermission you can totally just do while game.Workspace.BoolValue.value == true then. soaprocks2 75 — 10y
Ad
Log in to vote
-2
Answered by 10 years ago

Line 6 is incomplete. You need to end it with something. All you have for Line 6 is

if player.Character then

Just fill something in between Character and then and you should be alright.

0
What? NinjoOnline 1146 — 10y
0
There is nothing wrong with Line 6. coo1o 227 — 10y

Answer this question