Detect when player quits roblox studio

i made a Team create hat plugin but i need a way to detect when you quit roblox so i can delete the hats. Does anyone know how to detect when you quit roblox studio?

Store the player inside Game.Players in a table, and when the player leaves, the Player inside Game.Players will disappear, and you should be able to delete it.

like a player instance? there isnt a player instance as it is in roblox studio and is in edit mode.

Yes. it should only show up on team create sessions.
Capture

ah. thanks ima go try it now and see if it works.

it didnt delete the model.

	game.Players.PlayerRemoving:Connect(function(plr)
		if tostring(plr) == PlrName then
			Character:Destroy()
		end
	end)

:confused:

Use DesendantRemoved instead. That doesnt work because all scripts are paused in edit mode.

it didnt work. when i joined back in studio it was still there. and also the script does run because its running in a plugin.