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

Opening a Shop Gui by clicking on a textbutton not working, Suggestions?

--Made by airkor

local BuySword = game.StarterGui.ScreenGui.ShopGui:FindFirstChild("BuySwordFrame")

script.Parent.MouseButton1Click:connect(function()
		if BuySword.Visible then
			BuySword.Visible = true
	end
end)

Hi, I am trying to open a gui by clicking down on a button. Unfortunately, It would not work.

I tried numerous things but unfortunately, none worked, may anyone give me suggestions?

Edit: The local BuySword is not on another line of code as shown on here.

3 comments

0

perhaps it may be something small i'm mising

0

Try removing line 6 and line 8

0

didn't work

3 answers

You are trying to access the startgui when there is a server running. That won't do anything you have to access the playergui in player. This is how you would do it:

for i, player in pairs (game.Players:GetChildren()) do
local BuySword = player.PlayerGui.ScreenGui.ShopGui:FindFirstChild("BuySwordFrame")

script.Parent.MouseButton1Click:connect(function()
        if BuySword.Visible == false then
            BuySword.Visible = true
    end
end)
end

Hope it helps!

2 comments

0

thank you

0

No problem

Try using this instead of using if BuySword.Visible then BuySword.Visible = true

script.Parent.MouseButton1Click:connect(function()
 BuySword.Visible = not BuySword.Visible

By doing it, it just make it the opposite without using visible = true... full script

--Made by airkor

local BuySword = game.StarterGui.ScreenGui.ShopGui:FindFirstChild("BuySwordFrame")

script.Parent.MouseButton1Click:connect(function()
 BuySword.Visible = not BuySword.Visible
end)

Try this out, it should work...

One problem is your changing the StarterGui portion of it, that mean's when it's changed it won't be changed by the PlayerGui unless they reset, so you could do game.Players.LocalPlayer.ScreenGui.ShopGui:FindFirstChild("BuySwordFrame") in a LocalScript.

Another problem is on line six, you did if BuySword.Visible then, not if BuySword.Visible == false then.

Server script:

--Made by airkor

local BuySword = script.Parent.Parent:FindFirstChild("BuySwordFrame")

script.Parent.MouseButton1Click:connect(function()
        if BuySword.Visible == false then
            BuySword.Visible = true
    end
end)

Local script:

--Made by airkor

local BuySword = game.Players.LocalPlayer.PlayerGui.ScreenGui.ShopGui:FindFirstChild("BuySwordFrame")

script.Parent.MouseButton1Click:connect(function()
        if BuySword.Visible == false then
            BuySword.Visible = true
    end
end)

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