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.