Getting the Player's Position when they leave

  1. Im trying to set it up so when the player leaves they “drop” the custom tool I have made (by just making a clone and dropping it where their character was when they left)

  2. *Everything works except I cannot reference the position of the character since they left. ive never worked with this type of stuff before.

Is there a simple way to get the players position in the PlayerRemoving system or do I need another function or script to be getting their position?

game.Players.PlayerRemoving:Connect(function(player)
	local Char = game.Workspace:FindFirstChild(player.Name)
	local CharacterPos = Char.HumanoidRootPart.Position
	print(CharacterPos)

	if player.Carrying.Value == "True" then
		local ToolName = player.Carrying2.Value
		local NewTool = game.ReplicatedStorage.SpawnedItems:FindFirstChild(ToolName)
		NewTool.Name = ToolName
		NewTool.Parent = game.workspace
		NewTool.Position = CharacterPos -- This is the line that gets me, everything works I just cant spawn it at the position of the player who left.
	end
end)

Any help is appreciated, and if you need more info about other scripts I have let me know, but I think this is all thats needed to solve the issue.

You could just setup a loop and just constantly update the players position in a variable or a Vector3Value. And retrieve it when the player leaves.

Create a table then connect a CharacterAdded and store the players root in the table. Then once you do that, you can search through the table for the root parts in the PlayerRemoving connection, get their location then remove them from the table.

Examples are in one of the several previous version of this question