I need help with destroying a map

You can put it right before you choose a random map, im not sure why just getting a random map isnt working for you so possibly shuffling it beforehand could work

local Maps = game.ServerStorage.Maps:GetChildren()
local numMaps = #Maps

print(Maps)

for i = 1, numMaps do
    local randomIndex = math.random(i, numMaps)
    Maps[i], Maps[randomIndex] = Maps[randomIndex], Maps[i]
end

print(Maps)

Sample Output
image

I will try his script first and then I will try yours

Itā€™s because heā€™s choosing a random map once, obviously

Youā€™re cloning the map then destroying the clone.
Youā€™ll have to destroy the actual map, if thatā€™s what youā€™re looking to do.

Yeah but he never specified if he is making the round start instantly or if heā€™s even looping the code at all

Sorry, he already solved that portion of the script; heā€™s having trouble with the map being the same each time the round starts

So I put the script in the place that starts the round right?

2 Likes

If he destroys the original map how will he clone it again?

Why worry about it ā€¦ script is fine the way it is.
Make a a table, pick from the table, remove map from table. If you donā€™t want a repeat.

Yes you have to put the shuffling right before you actually try to get a random element inside of the maps folder

Do I need to delete the:

local ChosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChosenMap.SpawnLocation

No because that is what is getting the random map from the folder you have to keep everything you had just put the shuffle code I gave you at the top

something like this?


local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.SpawnLocation
local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChosenMap.SpawnLocation


--- Teleport ---

local Maps = game.ServerStorage.Maps:GetChildren()
local numMaps = #Maps

print(Maps)

for i = 1, numMaps do
	local randomIndex = math.random(i, numMaps)
	Maps[i], Maps[randomIndex] = Maps[randomIndex], Maps[i]
end

print(Maps)

InGame.Changed:Connect(function()
	if InGame.Value == true then
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = ChosenMap.SpawnLocation.CFrame
			ChosenMap:Clone().Parent = workspace
		end
	else 
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			workspace:FindFirstChild(ChosenMap.Name):Destroy()
		end 
	end
end)


--- Intermission and game Timer ---

local function roundTimer()
	while wait() do
		for i = 10, 1, -1 do
			InGame.Value = false
			wait(1)
			Status.Value = "Game starts in:"..i
		end
		for i = 10, 1, -1 do
			InGame.Value = true
			wait(1)
			Status.Value = "Time left:"..i
		end
	end
end

spawn(roundTimer)

No, this

local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.SpawnLocation

local Maps = game.ServerStorage.Maps:GetChildren()
local numMaps = #Maps

for i = 1, numMaps do
	local randomIndex = math.random(i, numMaps)
	Maps[i], Maps[randomIndex] = Maps[randomIndex], Maps[i]
end

local ChosenMap = Maps[math.random(1, #Maps)]
local ChoosenSpawn = ChosenMap.SpawnLocation

InGame.Changed:Connect(function()
	if InGame.Value == true then
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = ChosenMap.SpawnLocation.CFrame
			ChosenMap:Clone().Parent = workspace
		end
	else 
		wait(1)
		for _, player in pairs(game.Players:GetChildren()) do
			local character = player.Character
			character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			workspace:FindFirstChild(ChosenMap.Name):Destroy()
		end 
	end
end)


--- Intermission and game Timer ---

local function roundTimer()
	while wait() do
		for i = 10, 1, -1 do
			InGame.Value = false
			wait(1)
			Status.Value = "Game starts in:"..i
		end
		for i = 10, 1, -1 do
			InGame.Value = true
			wait(1)
			Status.Value = "Time left:"..i
		end
	end
end

spawn(roundTimer)

No, just create a random map everytime the minigame starts, dont shuffle it doesnt do anything

Yeah but the problem is this is the only script he has provided us and it looks like it just instantly starts a round there is no loop anywhere to be found in his code so this is the only explanation that i could think of to make it possibly get a new map each time this code is ran

edit: @MrOnlyKemal waiit i think your right i didnt see his map code beforeā€¦ he has to assign the map to a new variable and get another random map

Shuffling DOES NOT do anything, itā€™s just extra unneccesary code. If you want to make it random everytime the server starts, make a random map chooser, not shuffler

Bro its doing the same :frowning: I donā€™t know what to do

In some cases shuffling does actually work very well, but in this case your right it wont do anything because he isnā€™t assigning a new map when the round ends and a new one starts, I guess I just glossed over this fact

Try this :crossed_fingers:

local InGame = game.ReplicatedStorage.InGame
local Status = game.ReplicatedStorage.Status

local LobbySpawn = game.Workspace.Lobby.SpawnLocation
local Maps = game.ServerStorage.Maps:GetChildren()
local ChosenMap = nil
local ChoosenSpawn = nil

local function SetRandomMap()
    ChosenMap = Maps[math.random(1, #Maps)]
    ChoosenSpawn = ChosenMap.SpawnLocation
end

--- Teleport ---

InGame.Changed:Connect(function()
    if InGame.Value == true then
        wait(1)
        for _, player in pairs(game.Players:GetChildren()) do
            local character = player.Character
            character.HumanoidRootPart.CFrame = ChoosenSpawn.CFrame
            ChosenMap:Clone().Parent = workspace
        end
    else 
        wait(1)
        for _, player in pairs(game.Players:GetChildren()) do
            local character = player.Character
            character.HumanoidRootPart.CFrame = LobbySpawn.CFrame
            if ChosenMap then
                ChosenMap:Destroy()
            end
        end 
    end
end)

--- Intermission and game Timer ---

local function roundTimer()
    while wait() do
        for i = 10, 1, -1 do
            InGame.Value = false
            wait(1)
            Status.Value = "Game starts in:"..i
        end
        SetRandomMap() 
        for i = 10, 1, -1 do
            InGame.Value = true
            wait(1)
            Status.Value = "Time left:"..i
        end
    end
end

spawn(roundTimer)