For the past 5 hours I've been working on a Tool Equipping system, but for some reason I keep being sent the exact same Error. I think I've located the the source to the issue, but when ever I attempt to fix it never works.
The script is located in the StaterPlayerScripts.
The script only starts when an event called "SpawnEvent"
--Error
is not a valid member of Backpack "Backpack" - Client - LocalScript:66
local Players = game:GetService("Players")
local StarterGui = game:GetService("StarterGui")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = Players.LocalPlayer
local Events = ReplicatedStorage:WaitForChild("Events")
local SpawnEvent = Events:WaitForChild("SpawnEvent")
local PlrBackPack = Player:WaitForChild("Backpack")
local Weapons = {
Primary = "",
Secondary = "",
Melee = ""
}
local HasPrimary = false
local HasSecondary = false
local HasMelee = false
--------------------Tool Equipping
local function SetUp()
print(PlrBackPack:GetChildren())
for i, Tool in pairs(PlrBackPack:GetChildren()) do --Empty even though it shows and I know it isn't empty.
if Tool:isA("Tool") then
if Tool:GetAttribute("WeaponType") == "Primary" then
Weapons.Primary = Tool.Name
print(Weapons.Primary.Name)
elseif Tool:GetAttribute("WeaponType") == "Secondary" then
Weapons.Secondary = Tool.Name
print(Weapons.Secondary.Name)
elseif Tool:GetAttribute("WeaponType") == "Melee" then
Weapons.Melee = Tool.Name
print(Weapons.Melee.Name)
end
end
end
end
local function OnInput(input, Chat)
local Character = Player.Character
local Humanoid = Character.Humanoid
if Chat then return end
local GetKeyCode = input.KeyCode
if GetKeyCode == Enum.KeyCode.One then
if HasPrimary == false then
Humanoid:EquipTool(PlrBackPack[Weapons.Primary])
HasPrimary = true
HasSecondary = false
HasMelee = false
end
elseif GetKeyCode == Enum.KeyCode.Two then
if HasSecondary == false then
Humanoid:EquipTool(PlrBackPack[Weapons.Secondary])
HasPrimary = false
HasSecondary= true
HasMelee = false
end
elseif GetKeyCode == Enum.KeyCode.Three then
if HasMelee == false then
Humanoid:EquipTool(PlrBackPack[Weapons.Melee])
HasPrimary = false
HasSecondary = false
HasMelee = true
end
end
end
UserInputService.InputBegan:Connect(OnInput)
SpawnEvent.OnClientEvent:Connect(function()
SetUp()
wait(.1)
OnInput({KeyCode = Enum.KeyCode.One})-- initializes the force tool equipping
end)

7 comments
on line 34 print(PlrBackPack:GetChildren()), the table is empty right?
No it shouldn't be as it represents the players backpack, and in game that has tools in it.
I just did a test. For some reason its completely empty when it shouldn't be.
a copy of backpack is made after you respawn or something, try putting local PlrBackPack = Player:WaitForChild("Backpack") inside the SetUp function
I'll try it
It worked.
Such a simple solution, but I never knew the backpack was replicated.