Reset tool to Workspace on Death

I am making a game similar to Piggy and Spider, where the tools in it can be picked up by players, and they are very important. Currently, when a player leaves, the tool just gets destroyed. How would I make it so when a player leaves the game, the tool goes to the nearest ItemSpawn Point that is not being used.

This is an example of one of the key spawns when the game starts:

while true do
	local itemSpawns = game.Workspace.ItemSpawns:GetChildren()
	local orangeKeySpawn = itemSpawns[math.random(1, #itemSpawns)]
	if orangeKeySpawn.Used.Value == false then
		orangeKeySpawn.Used.Value = true
		game.Workspace.KeyDoors.Orange_Key.Handle.CFrame = orangeKeySpawn.CFrame
		break
	end
end

The tool is located inside the players Backpack. Each ItemSpawn block has a value inside it saying whether or not it is being used.

Thanks

You want to set the Parent of the Tool to Workspace if you want to move it out of the Player’s Backpack.

1 Like

When they’re leaving and have an unused tool you could duplicate the tool and move it to the nearest item spawn point.

You’ll need only the player removing event for this and some logic

1 Like

How would I use this in a PlayerRemoving event?

no time to type code but its like this:

on PlayerRemoved
tool.Parent = workspace
tool.CFrame = spawn.CFrame