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

How would I cycle through each map?

Asked by 7 years ago

This script works fine, but I want it to cycle through each map, rather than just picking one immediately. I want the ChosenMinigame value to be changed to a random map before 'choosing' one.

local minigames = game.ServerStorage:GetChildren()
local GameTime = 15
--if game.Players.NumPlayers > 1 then
    wait()

-----------------------------------Getting the minigames from ServerStorage
while true do

    local random = math.random(1, #minigames)
local gameChosen = minigames[random]:Clone()


print("The game is: ", gameChosen)

gameChosen.Parent = game.Workspace


game.Workspace.Value.Value = gameChosen.Name 


------------------------------------Checking for players with the same name
spawns = gameChosen:GetChildren()
for i, v in pairs(game.Players:GetPlayers()) do
    name = v.Name
    check = game.Workspace:FindFirstChild(name)
    if check then
        checkHumanoid = check:FindFirstChild("Humanoid")
        if checkHumanoid then
            if checkHumanoid.Health > 0 then
                check:MoveTo(spawns[i].Position)
            end
        end
    end

end

--Values for GUIs

    for i = GameTime, 1, -1 do
    game.Lighting.CountDownGui.Value = "Time left: " .. i  
    game.Lighting.ChosenMinigame.Value = "Minigame: " .. game.Workspace.Value.Value-- This holds the chosen minigame value
     -- The GUIs text changes based on these values.

    wait(1)
end
game.Lighting.CountDownGui.Value = "Game over!"
game.Lighting.ChosenMinigame.Value = "Intermission"

game.Workspace.Value.Value = "Intermission"





------------------------------------Giving players points
for y, x in pairs(game.Players:GetPlayers()) do

    inGame = x:FindFirstChild("InGame")
    if inGame then
        x.leaderstats.Points.Value = x.leaderstats.Points.Value + 100
        print(x.leaderstats.Points.Value)
        print(x.Name .. " wins!")

    else 
        print("NO INGAME VALUE")

    end
end
------------------------------------
gameChosen:Destroy()



wait(10)

end


--else
    print("MORE THAN ONE PLAYER NEEDED")


--end


1 answer

Log in to vote
0
Answered by 7 years ago

I have not tested this out yet, but hopefully you will understand the concept. Ok, so if I underatood yoir question correctly, you wanted to cycle through every map first, sort of like a preview, before officially choosing one. This can be easily done using a 'for' loop.

local mg_preview = {minigames} --create new table based on original table in order to use it for the cycle loop
for i, m in pairs (minigames) do -- this line doesn't really matter as you will only need it for going through the total number of maps.
local random = math.random(#mg_preview)
gameChosen = mg_preview[random]
-- preview the map: set it in workspace, orbit around it, etc.
table.remove(mg_preview, random) -- remove the previewed map after so that you can preview the others.

end
Ad

Answer this question