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

How do I get this TextButton and ScreenGui script to work?

Asked by 3 years ago

Code:

local playerGui = game.Players.LocalPlayer.PlayerGui
local Clicked = playerGui.OpenPurchasesGui:WaitForChild("TextButton")
local DB = false
local PurchasesGui = playerGui:WaitForChild("PurchasesGui")
local Visible = PurchasesGui.Enabled
warn(Visible)

Clicked.Activated:Connect(function()
    warn("Clicked")
    if not DB then
        DB = true
        if Visible == true then
            Visible = false
            warn(Visible)
        else
            Visible = true
            warn(Visible)
        end
        wait(.5)
        DB = false
    end
end)

I don't understand this. In output it says clicked and then true when it's changed to true and false when it's changed to false. When I check in the PlayerGui and look at ScreenGui, nothing has changed no matter what. I seriously don't know what's going on.

2 answers

Log in to vote
0
Answered by 3 years ago

From my experiences, you cannot set a property as a variable, so instead of using the variable "Visible" you'll just have to use .Enabled in your script over and over.

annoying? yes. avoidable? no.

local playerGui = game.Players.LocalPlayer.PlayerGui
local Clicked = playerGui.OpenPurchasesGui:WaitForChild("TextButton")
local DB = false
local PurchasesGui = playerGui:WaitForChild("PurchasesGui")
-- local Visible = PurchasesGui.Enabled
warn(PurchasesGui.Enabled)

Clicked.Activated:Connect(function()
    warn("Clicked")
    if not DB then
        DB = true
        if PurchasesGui.Enabled == true then
            PurchasesGui.Enabled = false
            warn(PurchasesGui.Enabled)
        else
            PurchasesGui.Enabled = true
            warn(PurchasesGui.Enabled)
        end
        wait(.5)
        DB = false
    end
end)
Ad
Log in to vote
0
Answered by 3 years ago

You aren't able to change the properties of an object like that.

You are doing

local Visible = PurchasesGui.Enabled
Visible = false

While it should be the following:

local Visible = PurchasesGui
Visible.Enabled = false

Answer this question