Why doesn't this script work?

I have a script that makes some ScreenGui Enabled, (The Update Log) but the Gui has enabled checked and It isn’t showing the Ui located in the ScreenGui. Here’s the code:

local Button = script.Parent
local UpdateGUI = game.StarterGui.UpdateGui

local Opened = false

local function OpenUpdates()
	if Opened == false then
		UpdateGUI.Enabled = true
		Opened = true
		print("Updates Opened")
	end
end
local function CloseUpdates()
	if Opened then
		print("Updates Closed")
		UpdateGUI.Enabled = false
		Opened = false
	end
end
Button.MouseButton1Click:Connect(OpenUpdates)
Button.TouchTap:Connect(OpenUpdates)
Button.MouseButton1Click:Connect(CloseUpdates)
Button.TouchTap:Connect(CloseUpdates)

Thank you, everything helps.

It seems to me that you are initializing 2 mouse click events at once, which is wrong, you can try this kind of code, if there are problems, let me know

local Button = script.Parent
local UpdateGUI = game.StarterGui.UpdateGui

local Opened = false

local function ToggleUpdates()
	if not Opened then
		UpdateGUI.Enabled = true
		Opened = true
		print("Updates Opened")
    else
     	print("Updates Closed")
		UpdateGUI.Enabled = false
		Opened = false
	end
end

Button.MouseButton1Click:Connect(ToggleUpdates)
Button.TouchTap:Connect(ToggleUpdates)
1 Like

Where is this script located? Is it server-sided or client-sided?

If it’s server-sided, changing the gui in StarterGui won’t change it for all of the players currently in the game.
If you want to achieve that, either do this in a LocalScript (first code sample below) or use a loop to get all the players (second code sample below)

Code samples:

-- (a) LocalScript in StarterPlayerScripts
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local UpdateGUI = player.PlayerGui.UpdateGui
UpdateGUI.Enabled = true
-- (b) Script in wherever you want it stored
local Players = game:GetService("Players")
for _, player in ipairs(Players:GetPlayers()) do
    local UpdateGUI = player.PlayerGui.UpdateGui
    UpdateGUI.Enabled = true
end

On line 2, you’re getting the StarterGui service. Instead, you should reference the player’s PlayerGui, using:

local UpdateGUI = game.Players.LocalPlayer.PlayerGui.UpdateGui

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.