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