I am trying to clone a tool when a player spawns and place it in the Player’s backpack. This is the script I used.
game.Players.PlayerAdded:Connect(function(Player)
local clonetool = game.ServerStorage.TestTool:Clone()
clonetool.Parent = game.Players[Player.Name].Backpack
end)
For some reason, the tool won’t go into the Player’s backpack. If I set the parent of the tool to Server Storage then it works fine but in the backpack it doesn’t work.
You will most likely want to use the CharacterAdded event on Player. This guarantees the player’s character will be available, and will allow you to parent a tool to the player’s backpack. Also, if the player resets, it’ll give them the tool again.
Add prints, is the code even running? Sometimes playeradded is connected AFTER your player has already been connected to the server. Also if there is a “Player” parameter being passed in you don’t have to do Players:FindFirstChild(Player.Name).Backpack. Just do Player:WaitForChild(“Backpack”).
Like others have mentioned, you should clone the tool after the CharacterAdded event is fired. Your original code wouldn’t work because the player’s Backpack is destroyed and then created every time the player’s character is created.
I realize that this has been solved, but I rather post this than have it go to waste. Here’s a quick example that I whipped up:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
local backpack = player:WaitForChild("Backpack")
local cloneTool = game.ServerStorage.TestTool:Clone()
cloneTool.Parent = backpack
end)
end)