Having trouble cloning item into player's backpack

Hi guys,
I am having troubles cloning an item from the replicatedstorage and storing it into the player’s backpack.

Code

This is what it printed
Screenshot 2024-01-21 201216

As you can see. In my backpack, I don’t get a tool in my backpack. Why is this the case?

Did you check if you see other tools in your inventory if you put them in starter pack? Like without the script just basicly in sp

Hi v3core,
I can confirm that I have tried that and when I put my tool in my starterpack. It indeed works. This is a playeradded event

Well, you’re creating a clone, but you are parenting the original. Start by fixing that.

2 Likes

According to that you want to use playeradded function or event then you could try this.

game.Players:PlayerAdded:Connect(function(plr)
    wait()
    local clone = game.ReplicatedStorage:WaitForChild("Tool"):Clone()
    clone.Parent = plr.Backpack
end)
1 Like

I agree with what v3core did, instead of adding the cloned tool into the player’s backpack, you add the tool you were trying to clone, meaning that when you do it, it just doesn’t exist.

Alongside your .PlayerAdded event, you would also want to add a .CharacterAdded event as well, because Backpack is directly linked with the player’s character. The program is correctly adding the Tool into the player’s backpack, but since the character has not yet loaded, the Tool will not be found in said Backpack.

I have amended your code to include this change:

game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterAdded:Connect(function(character)
		local tool = game:GetService("ReplicatedStorage").Tool
		local clone = tool:Clone()
		
		clone.Parent = player.Backpack
		-- Make sure to use the variable 'clone' instead of the variable 'tool'
		
		print(player.Backpack:GetChildren())
	end)

end)
1 Like

Hi D4rk,
Thank you for your response.

I have taken your amended code and it indeed works. I totally forgotten to check if the player character has been loaded. Alternatively, I can write local xVariable = player.Character player.CharacterAdded:Wait()

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