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

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

Asked by
airkor 10
8 years ago
--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.

0
perhaps it may be something small i'm mising airkor 10 — 8y
0
Try removing line 6 and line 8 Potlon 35 — 8y
0
didn't work airkor 10 — 8y

3 answers

Log in to vote
0
Answered by 8 years ago

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!

0
thank you airkor 10 — 8y
0
No problem docrobloxman52 407 — 8y
Ad
Log in to vote
0
Answered by
yoshi8080 445 Moderation Voter
8 years ago

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...

Log in to vote
0
Answered by 8 years ago

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)

Answer this question