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

Can't get a button to toggle the ScreenGUI?

I have a Gui in StarterGui (Parent Trees below.. triggerScript is a localScript). storeTrigger is a textButton that when the user clicks the button, it toggles visibility for the store Gui. The button and the rest of the store share the same storeStock Parent.

game.StarterGui.storeStock.storeBG.marketTitle game.StarterGui.storeStock.storeTrigger.triggerScript

local btnToggle = game.StarterGui.storeStock.storeTrigger
local visibleState = false

function toggleGui(isVisible)
	game.StarterGui.storeStock.storeBG.Visible = isVisible
	if isVisible == true then
		visibleState = false
	else
		visibleState = true
	end
end

btnToggle.MouseButton1Down:connect(function()
	toggleGui(visibleState)
end)

When I click on the button, nothing happens. No error messages in output or anything. Can anyone tell me what I'm doing wrong?

1 comment

1

You need to access the player's gui. Not the starter gui. The starter Gui contains all the gui elements that are given to the player when the join/respawn.

1 answer

✓ Accepted answer

That is because you are using StarterGui instead of PlayerGui. In brief explanation, PlayerGui is contained with the current objects located in StarterGui, if a Gui element is changed in PlayerGui then the changes are visible through screen.

local player = game.Players.LocalPlayer

local btnToggle = player.PlayerGui:WaitForChild("storeStock").storeTrigger
local visibleState = false

function toggleGui(isVisible)
    player.PlayerGui:WaitForChild("storeStock").storeBG.Visible = isVisible
    if isVisible == true then
        visibleState = false
    else
        visibleState = true
    end
end

btnToggle.MouseButton1Down:connect(function()
    toggleGui(visibleState)
end)

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