game.ReplicatedStorage.ToggleItem.OnServerEvent:connect(function(player, obj, toggleType) if toggleType == "Equip" then for i,v in pairs(player.PlayerGui.Inventory.Background:GetChildren()) do --This is the line if string.sub(v.Name, 1, 5) == "Image" then if v.Item.Value == obj.Name then player.Character.Humanoid:EquipTool(obj:Clone()) end end end elseif toggleType == "Unequip" then player.Character.Humanoid:UnequipTools() end end)
On the line indicated above in the code, I always get an error. I checked my hierarchy and everything, it is correct. But for some odd reason, it always says 'Inventory is not a valid member of PlayerGui'. Any clue on how to fix this problem? Thanks!
(PS, this is a Server Script!)
I'm not exactly sure but this has happened once to me. Are you sure there is an GUI called Inventory in the player? If so then I think you need :WaitForChild because it may not have loaded yet.
Here's the edited version of your script with WaitForChild's;
game.ReplicatedStorage:WaitForChild("ToggleItem").OnServerEvent:connect(function(player, obj, toggleType) if toggleType == "Equip" then for i,v in pairs(player.PlayerGui:WaitForChild("Inventory").Background:GetChildren()) do --This is the line if string.sub(v.Name, 1, 5) == "Image" then if v.Item.Value == obj.Name then player.Character.Humanoid:EquipTool(obj:Clone()) end end end elseif toggleType == "Unequip" then player.Character.Humanoid:UnequipTools() end end)
If this somehow worked then please upvote and accept answer :P.
You do not have the inventory as in PlayerGui. The inventory is a core gui, that is why it says your inventory isen't a valid member. I am not a advanced scripter but when you equip a item it dosen't go to the PlayerGui. Try to look at the wiki.