How to get a character's tool?

Server:

game.Players.PlayerRemoving:Connect(function(Player)
	local toolInHand = Player.Character:FindFirstChildOfClass("Tool")
	
	print(Player, Player.Character)
	print(toolInHand)
	
	if toolInHand then
		toolInHand.Parent = Player.Backpack
	end
end)

So here I have a part of the script to get the player’s tool in hand, but it writes nil in the output for some reason. Why? P.S. if what I have in another script also writes nil.

3 Likes

Why are you wanting the player to be removed from the game, then check what tool the player has?

2 Likes

because I want when a player leaves the game to move his item from his hand to another place to save it that way.

2 Likes

I’m confused, why would you need to save the players tool to another place?

1 Like

The tool could be getting destroyed before the player instance is removed. Characters are probably removed right before the player is

1 Like

explaining. I have a store of different items in my game. A player can go to the store and buy an item with currency. Then he can equip it. BUT!!! I need that when you exit the game saved what things he bought and actually that in the store it is also shown. That’s why I save the current item of the player, and others. I hope I explained well)

1 Like

Yeah, that’s what I thought, too. BUT!!! I have a script to equip an item from the store:

local equipped = player.Character:FindFirstChildOfClass("Tool")
	
	print(equipped)

Here I’m just looking for an item in the player’s hand, and I only call it when the equipment button is pressed to replace the item. But it still equals nil

1 Like

has it ever occoured to you backpack, a child of player, would be removed when the player is removed?

1 Like

That’s not how it works. You would need to use Datastores.

1 Like

and do you know any articles on how to save items specifically, I know how to save Value, I also use dataStore for that. But saving an item is quite different, at least I think so.

1 Like
  1. a value of the name of the item
  2. when buy, change the bool to true

OR

A list of what the player owns

1 Like

Exactly what he said. Obviously it’s more complicated than that. But that’s the gist of it. Make a value for each of the tools in the game, if the players buy that tool then get the value with the same name as the tool and set it to true. When the players has joined the game again, loop through each value and see if it’s true, if one of the values are true, then get the tool with the same name as the value, then clone it to the players backpack.

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.