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

How would I destroy all models after the round ends?

Asked by 2 years ago
Edited 2 years ago

I am currently making a game but I set up a round system and it will clone a folder from ServerStorage but I can't make it delete all the models that were spawned in 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.

0
Which function do you want to remove all the models? BuildAboatTest124 51 — 2y
0
RoundCleanup on line 68 Puffyjasonrocks84 39 — 2y

Answer this question