Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

1 comment

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

1 answer

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

2 comments

0

Please use local variables/functions :P

0

That's a strange grievance.

This discussion is preserved as it was. New answers, comments, and votes are closed.