I am trying to get the player’s backpack’s tools using a server script. My script has no errors, however it still gives me an error when I try to index an existing item in the backpack. What did I do wrong?
Script:
local function onPlayerAdded(player)
local bakcpack = player:WaitForChild("Backpack")
print(bakcpack:GetChildren())
local blaster = bakcpack.Blaster
blaster:SetAttribute("Ammo", 5)
end
Players.PlayerAdded:Connect(onPlayerAdded)
Items to backpack are added when your character is spawning.
Try this:
local function onCharacterAdded(player)
task.wait()
local backpack = player:WaitForChild("Backpack")
print(backpack :GetChildren())
local blaster = backpack .Blaster
blaster:SetAttribute("Ammo", 5)
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
Players.PlayerAdded:Connect(onPlayerAdded)