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

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

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

✓ Accepted answer

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)

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

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