Removing models which aren't a players

I’m trying to remove a model that is placed inside a folder on the server and given a player name. So basically, on the client it checks to see if that item is the players. If it isn’t the players, then it deletes it on (on their client) however I get this warning

Something unexpectedly tried to set the parent of Player1 to NULL while trying to set the parent of Player1

local function NewPizza(pizza)
	print('New pizza added')
	if pizza.Name ~= Player.Name then
		print('Not the players')
		-- If not players pizza, destroy it
		pizza:Destroy()
	end
end

Doing some testing on my own, I didn’t encounter any issues. My testing format is I have a Folder inside Workspace with 4 Parts, all but one having usernames that aren’t mine.

LocalScript inside StarterPlayerScripts:

local player = game.Players.LocalPlayer

for i, item in pairs(workspace.ServerItems:GetChildren()) do
	if item.Name ~= player.Name then
		item:Destroy()
	end
end

And it seemed to work fine for me.

Looking at your error, it seems to be that the “pizza” parameter is being set to the player, for some reason? Maybe check the function that calls NewPizza to see if there’s an issue there.

this function fires when the item is added. Items aren’t there at the start of game

Maybe add a check for nil then? Just a simple

if not pizza then return end

might be enough to make it not fail at the start.

Still get the warning

local function NewPizza(pizza)
	-- Check if pizza exists
	if not pizza then return end
	
	-- If not players pizza, destroy it
	if pizza.Name == Player.Name then return end
	
	pizza:Destroy()
end

PizzaHolder.ChildAdded:Connect(NewPizza)

If that’s the case, that means that:
A) The pizza exists
B) The pizza’s name is the player’s name

Which is confusing because you’ve stated that the items don’t exist. Not sure how much more I can diagnose beyond this point without seeing more of the script because it seems like one of those checks would have snagged it if that’s the case.