The 2nd code in the documentation of backpack which is:
local Players = game:GetService("Players")
local function giveTool(player, tool)
local backpack = player:FindFirstChildOfClass("Backpack")
if backpack then
tool.Parent = backpack
end
end
local function onPlayerAdded(player:Player)
local tool = Instance.new("Tool")
giveTool(player, tool)
end
Players.PlayerAdded:Connect(onPlayerAdded)
will not work because the backpack resets every time the character is loaded, you can test it out yourself
Hello @YkKasper, thank you for flagging this! We are updating the code sample to the following:
local Players = game:GetService("Players")
local function onCharacterAdded(character)
local player = Players:GetPlayerFromCharacter(character)
local tool = Instance.new("Tool")
local backpack = player:FindFirstChildOfClass("Backpack")
tool.Parent = backpack
end
local function onPlayerAdded(player)
if player.Character then
onCharacterAdded(player.Character)
end
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)