Tool not cloning into backpack

I have some code that will clone a tool from Server storage to the player’s backpack. The problem is once the remote event is fired, the tool isn’t in the backpack. The cloned tool just disappeared, with no errors, nothing.

game.ReplicatedStorage.GiveTool.OnServerEvent:Connect(function(player)
	local toolToGive = game.ServerStorage.Tool
	local toolClone = toolToGive:Clone()
	toolClone.Parent = game.Players[player.Name].Backpack
end)

I see some posts saying I should add (see below) but I wanted to fire it based on a remote event.

player.CharacterAdded:Connect(function()

...

end)
1 Like

You do not need to access the player from the Player service. The first argument is the player, so you could do player.Backpack instead.

Do you have a local script to fire the GiveTool event?

1 Like

Try printing something. And send the result.

You should only add the second portion if you think that the player might be dead when they are receiving the tool.

Your code looks fine, except for the what was mentioned in the first reply about changing game.Players[player.Name].Backpack to just player.Backpack, as OnServerEvent takes in a player object.

I think your issue is that your remote event is not being fired. You might want to do a test to make sure it is, and that it goes through the code without any errors.

Here is the localscript:

game.ReplicatedStorage.GiveTool:FireServer()

If you are using a click detector, use this:

script.Parent.ClickDetector.MouseClick:Connect(function(player)
if player then
local tool = game.ReplicatedStorage.ToolName:Clone() 
tool.Parent = player.Backpack
script.Parent:Destroy()
end
end)

both use of script/local script is correct, except that you are executing it too fast.
put atleast a 5 seconds wait or smth

Why do you do script.Parent:Destory() ?

Where is the click detector based? If it is inside of a part, then it makes sense to destroy it, but if not, then that’s fine.