Pet models are not deleting properly

I have a script where i want to delete all pets a player has. well, the pet models are staying in workspace they just aren’t following the player anymore. they’re still stored in the pets folder as well. not sure what to do with this.

module function

function module.DeleteAllPets(player)
	if isServer then
		table.clear(module.pets, table.find(module.pets, player))
		
		local folder = workspace.Pets:FindFirstChild(player)
		if folder ~= nil then
			for _, v in pairs(folder:GetChildren()) do
				if v:IsA('Model') then
					v:Destroy()
				end
			end
		end
	else
		return petInfoRemote:InvokeServer("DeleteAllPets", player)
	end
end

local

deleteAllButton.MouseButton1Down:Connect(function()
	for _, v in pairs(scrollingFrame:GetChildren()) do
		if v:IsA("Frame") then
			v:Destroy()
		end
	end
	midFrame:ClearAllChildren()
	PetModule.DeleteAllPets(game.Players.LocalPlayer)
end)
2 Likes

I am not really a scripter but try to check if the model got destroyed. If it hasn’t run the function / script again.

3 Likes

i figured it out. i’ll repost the answer as a solution. hold up.

2 Likes

it was because of player. player, in this case, is an instance. so it would be…

local folder = workspace.Pets:FindFirstChild(player.Name)

or could do

local folder = workspace.Pets:FindFirstChild(tostring(player))
2 Likes