I’m currently trying to make a simple equip system. Apparently, the :GetChildren()
method is not working. I have never encountered something like this before. When the function is ran, (which is when i press 3) It returns a nil table even though I can clearly see in the explorer tab that there are 3 tools in my player’s backpack.
elseif input.KeyCode == Enum.KeyCode.Three then
-- Equip Melee Weapon
print("pressed 3")
print(backpack:GetChildren())
for i, v in backpack:GetChildren() do
print("checking for itemslot")
if v:FindFirstChild("ItemSlot") then
if v.ItemSlot.Value == "Melee" then
player.Character.Humanoid:EquipTool(v)
end
end
end
end
Output:
This actually appears to be an issue with the game not detecting children of Backpack
because previously I used a recursive :FindFirstChild()
which also did not work, likely due to it detecting nil as a child of Backpack. Still do not understand why it is nil
.
UPDATE
I found the problem which, makes absolutely no sense. Apparently defining backpack with a different variable breaks something, which again, makes absolutely no sense seeing as a variable is just a different way of stating something.
This does not work:
local player = game.Players.LocalPlayer
local backpack = player.Backpack
This does work:
local backpack = game.Players.LocalPlayer.Backpack
logically, it should work both ways seeing as player
and game.Players.LocalPlayer
are precisely the same thing, but who knows. If you are passing by and know why this -presumably a bug- occurs please let me know.