ClearAllChildren() not removing models?

Hello, so i was using :ClearAllChildren() to remove everything from a viewportframe and it removes everything but not models the script is not a local script here is my script:

local folder = game.ReplicatedStorage:WaitForChild("AllPets")
local frame = script.Parent
local template = script.Parent.ScrollingFrame.Template
local player = script.Parent.Parent.Parent.Parent
local infoframe = script.Parent:FindFirstChildOfClass("Frame")
local character = player.Character or player.CharacterAdded:Wait()
for _, pet in pairs(folder:GetChildren()) do
	local newtemplate = template:Clone()
	newtemplate.Name = pet.Name
	newtemplate.PetName.Text = pet.Name
	newtemplate.Parent = frame.ScrollingFrame
	local changetext = newtemplate.TextLabel.ChangeText
	changetext.Disabled = false
	newtemplate.MouseButton1Click:Connect(function()
		infoframe.ViewportFrame:ClearAllChildren()
		wait(5)
		for _, item in pairs(infoframe.ViewportFrame:GetChildren()) do
			if item:IsA('LocalScript') then
				item:Destroy()
			end
		end
		infoframe.Name = newtemplate.Name
		local s = newtemplate.ViewportFrame.LocalScript:Clone()
		s.Disabled = true
		s.Parent = infoframe.ViewportFrame
		s.Disabled = false
	end)
end

Thank you!

2 Likes

You can try using this instead:

local removeFolder = --what you want to remove
for i,v in pairs(removeFolder:GetChildren()) do
v:Destroy()
end
1 Like

Clear all children only removes BaseParts, if you want to delete everything, I’d recommend using @DindinYT37’s method.

Never mind i don’t know why but when i changed the script to a local script it worked.