How to disable a GUI

I am trying to disable this gui and for some reason it is not working. When I test the game and manually uncheck the enable gui box it goes away and when I run this script tell it to change the name of the gui it works but for some reason I can’t disable it using script.

local gui = player1.PlayerGui:FindFirstChild("LeaveCourt1Spot1A")
		gui.Enabled = false

This exact code is working on other parts of the game also. Does anyone know what might be wrong.

Hello, is player1 the local player?

Yes player1 is the local player and all of this is in a script in the workspace

You cannot get the local player from a script in the workspace. It only works in a localscript.

This is the full block of code. What it does is wait until a team has 1 player which is “TeamNumber” then it makes a table of every player in that team and calls the first player in that team player1 and when I print it in game it says “emrek”. And I can change other values like the name of the GUI.

Team1.PlayerAdded:Connect(function(Player)
	if #Team1:GetPlayers() == TeamNumber and #Team2:GetPlayers() == 0 then
		local players = Team1:GetPlayers()
		local player1 = players[1]
		local humanoidRoot = player1.Character.HumanoidRootPart
		local spawnSpot1A = court.SpawnSpot1A
		local gui = player1.PlayerGui:FindFirstChild("LeaveCourt1Spot1A")
		gui.Enabled = false
		humanoidRoot.CFrame = spawnSpot1A.CFrame * CFrame.new(0,10,0)
		humanoidRoot.CFrame = humanoidRoot.CFrame * CFrame.Angles(0,math.rad(180),0)
	end
end)

try to use a remotevent and do all gui things with a local script. everything with gui should be done in localscripts.

2 Likes

This should be throwing an error, because gui will be nil from the server side.

@icedcobraa is right—use a RemoteEvent to tell the client that it needs to update its own GUI. The server can’t update the client’s GUI for it.