Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my script say that my GUI is not a valid member?

Asked by 7 years ago
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!)

0
What is the specific error? User#10445 15 — 7y
0
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. RootEntry 111 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago

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.

0
I have no idea, this is the dumb part, it just is an infinite yield ;(((( thehybrid576 294 — 7y
0
try naming it something else, like InventoryGUI BlackOrange3343 2676 — 7y
Ad
Log in to vote
0
Answered by
RootEntry 111
7 years ago

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.

0
No, Backpack is the CoreGui you speak of and it isn't located in PlayerGui, it is located in the Player thehybrid576 294 — 7y

Answer this question