(UNSOLVED) How would I destroy all models after the round ends

I am currently making a game right now I have a round system that will spawn in a folder of models once the round starts but I can’t get the models to destroy after the round has ended I set the parent of all the models to workspace using the clone command here is my code:

local RoundLength = 180
local IntermissionLength = 60
local Lobby = workspace.LobbySpawn.Lobby.CFrame
local Spawnpoints = workspace.GameSpawnPoints:GetChildren()
local Brigatine = game.ServerStorage.Boats
local RespawnTime = 2.5



local InRound = Instance.new("BoolValue")
InRound.Name = "Inround"
InRound.Parent = game.ReplicatedStorage
local Status = Instance.new("StringValue")
Status.Name = "Status"
Status.Parent = game.ReplicatedStorage




local function SpawnPlayer(Character, _CFrame)
	
	if InRound.Value == true then
		
	for _, object in pairs(Brigatine:GetChildren()) do 
		Brigatine = object:Clone()
		Brigatine.Parent = workspace
		end
	else
		
		end
	
	
	
	
	local Root = Character:WaitForChild("HumanoidRootPart")
	if _CFrame then
		repeat
			Root.CFrame = _CFrame + Vector3.new(0, 4.5, 0)
			wait()
		until
		(Root.Position - _CFrame.Position).Magnitude < 5
		return
	end
	local RandomSpawn = Spawnpoints[math.random(1, #Spawnpoints)].CFrame + Vector3.new(0, 4.5, 0)
	repeat
		Root.CFrame = RandomSpawn
		wait()
	until
	(Root.Position - RandomSpawn.Position).Magnitude < 5
end

local function RoundCleanup()
	for _, Player in pairs(game.Players:GetPlayers()) do
		Player:LoadCharacter()
	end
end

local function StartRound()
	InRound.Value = true
	for _, Player in pairs(game.Players:GetPlayers()) do
		Player:LoadCharacter()
	end
	for i = RoundLength, 0, -1  do
		wait(1)
		Status.Value = "Game - "..i.." seconds left!"
	end
	InRound.Value = false
	RoundCleanup()
	if InRound then
		local Humanoid = Character:WaitForChild("Humanoid")
	end
end

local function StartIntermission()
	for i = IntermissionLength, 0, -1  do
		wait(1)
		Status.Value = "Intermission - "..i.." seconds left!"
	end
	StartRound()
	StartIntermission()
end







game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if InRound.Value then
			SpawnPlayer(Character)
		else
			SpawnPlayer(Character, Lobby)
		end
		local Humanoid = Character:WaitForChild("Humanoid")
		Humanoid.Died:Connect(function()
			wait(RespawnTime)
			Player:LoadCharacter()
		end)
	end)
end)


StartIntermission()

Thanks.

1 Like

assuming when the round ends you want the folder to be cleared, replace RoundCleanup() with this:

local function RoundCleanup()
	for _, Player in pairs(game.Players:GetPlayers()) do
		Player:LoadCharacter()
	end
    for _, Model in pairs(folder:GetChildren()) do
        Model:Destroy()
    end
end

by the way,

I set the parent of all the models to workspace using the clone command

i can’t seem to find this in your code. could you provide some more info? your question was kind of confusing