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

Why won't this GUI turn invisible when there's a tool in the starterpack?

Asked by 7 years ago
Edited by OldPalHappy 7 years ago

The purpose of this script is to make the GUI (script.parent) invisible when the player has a tool in their starterpack. Can someone show me where I went wrong?

Thanks a million, Marcus


man = game.Players.LocalPlayer
c = man.Backpack:GetChildren()

function characterAdded ()

    if 1==1 then
    for i = 1,#c do
            if c[i].className == "Tool" or c[i].className == "HopperBin" then
                local gog = game.StarterPack:findFirstChild(c[i].Name)
                if gog == nil then
                    script.parent.Visible = false
                end
            end
    end
end

man.PlayerAdded:connect (characteradded)
0
I edited your question. Please add a codeblock yourself in the future: https://forum.scriptinghelpers.org/topic/82/how-to-format-questions-answers-on-the-main-site OldPalHappy 1477 — 7y

1 answer

Log in to vote
0
Answered by
cabbler 1942 Moderation Voter
7 years ago

You'll have to repeat c = man.Backpack:GetChildren() every time you want the children, or else you always use the same table. You also might have to wait for the backpack to load. Here is your code with a few other other revisions.

player = game.Players.LocalPlayer --better name
bp = player:WaitForChild('Backpack')
c = bp:GetChildren()

function characterAdded()
    --why check 1=1 ?
    c = bp:GetChildren()
    for _,v in pairs(c) do --using pairs may be better here
        if v:IsA("Tool") or v:IsA("HopperBin") then --:IsA is useful!
            local gog = game.StarterPack:FindFirstChild(v.Name)
            if not gog then
                script.parent.Visible = false
            end
        end
    end
end

player.CharacterAdded:connect(characterAdded) --the correct event
0
Please use local variables/functions :P OldPalHappy 1477 — 7y
0
That's a strange grievance. cabbler 1942 — 7y
Ad

Answer this question