Screen GUI Not Disappearing/Visibility Not Being Executed in Script

Hello, I am trying to make my starting menu UI disappear when the player presses the play button. I have a local script inside of my starting menu screen GUI that, when the user presses the play button, fires an event to a server script that checks to see if the attribute on the workplace warrants the user to be spawned into the game or forces them to spectate until the round is over. I have a tween that fades a black screen over the UI after the play button is pressed, waits for 1 second, fires the event, waits another second, disables the visibility of the starting menu, and then fades the black screen out.

The problem I am facing is that the starting menu never goes away. There are no errors in the console, but when I used breakpoints to find the error, it seems like the script crashes (I’m relatively new to scripting so I’m not sure of the correct terminology or if that’s even what’s happening) after the event is fired, and the thread never executes the line to set the visibility of the GUI to false. I have also tried putting the visibility line inside of the event to see if that would work but it didn’t. I have also made sure that ResetOnSpawn is disabled for the screen GUI. Another thing is that the black screen does fade out, which led me to believe that the thread got to the final line, but when i commented this line out, the screen still faded out regardless (Should it do this?).

I have attached a video of me using break points to find the problem as well as the local and server scripts used. Any help will be greatly appreciated.

Local Script(For starting menu gui):

-----------------------------
-- SERVICES --
-----------------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
-----------------------------
-- VARIABLES --
-----------------------------
local gameStateEnum = require(ReplicatedStorage.Modules.Enums.GameStateEnum)

local startingMenu = script.Parent

local speactateFrame = startingMenu.SpectateFrame
local storeFrame = startingMenu.StoreFrame
local blurImg = startingMenu.ImageLabel

--buttons
local playButton = blurImg.PlayButton
local spectateButton = blurImg.SpectateButton
local storeButtton = blurImg.StoreButton

--events
local respawnEvent = ReplicatedStorage.Remotes.GUI.Respawn
-----------------------------
-- PRIVATE FUNCTIONS --
-----------------------------
local function fade(uiElement, goal)
	local tween = TweenService:Create(uiElement, TweenInfo.new(0.5), goal)
	tween:Play()
end

-----------------------------
-- HANDLERS --
-----------------------------
playButton.Activated:Connect(function()
	
	if workspace:GetAttribute("GameState") == gameStateEnum.START_INTERMISSION or gameStateEnum.INTERMISSION then
		--its okay to spawn
		fade(startingMenu.Black, {BackgroundTransparency = 0})
		task.wait(1)
		respawnEvent:FireServer()
		task.wait(1)
		blurImg.Visible = false
		fade(startingMenu.Black, {BackgroundTransparency = 1})
	else
		--its not okay to spawn
	end
end)

Server Script(For remote event and assigning teams/workspace attributes):

-----------------------------
-- SERVICES --
-----------------------------
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Teams = game:GetService("Teams")
local PlayerService = game:GetService("Players")
-----------------------------
-- VARIABLES --
-----------------------------
local gameStateEnum = require(ReplicatedStorage.Modules.Enums.GameStateEnum)

--events
local respawnEvent = ReplicatedStorage.Remotes.GUI.Respawn

-----------------------------
-- HANDLERS --
-----------------------------
PlayerService.PlayerAdded:Connect(function(player)
	player.Team = Teams.Dead
	
	player.CharacterAdded:Connect(function(character)
		character.Humanoid.Died:Connect(function()
			player.Team = Teams.Dead
		end)
	end)
end)

respawnEvent.OnServerEvent:Connect(function(player)
	if workspace:GetAttribute("GameState") ~= gameStateEnum.START_INTERMISSION and workspace:GetAttribute("GameState") ~= gameStateEnum.INTERMISSION then
		return
	end
	player.Team = Teams.Alive
	player:LoadCharacter()
end)
-----------------------------
-- MAIN --
-----------------------------
workspace:SetAttribute("GameState", gameStateEnum.START_INTERMISSION)

After thinking a bit and looking over the code, I wasn’t able to identify any obvious issues, however, can you add a WaitForChild for blurImg and test it.

Let me know the result.

Tried it and it still does the same thing.

Is the whole main gui a single ImageLabel? can you try setting the visibility to false in a blank script and see if that works.

Below is all that is in the ImageLabel:
image

I have also tried and was successful in getting the GUI to disappear in another local script by itself:

1 Like

I’ve looked over your code many times, I’m really unsure why this would be happening.

My idea is to try to restructure your code a bit and see if you can get any different outcome.

Hopefully, you get to resolve this issue, sorry for not being much help.

No problem, I appreciate you taking time to look it over.

1 Like

Seems like the ScreenGUI can’t be under a folder as the GUI itself won’t be reset when the player respawns but the folder will.

2 Likes

Wow, that’s all it was, thanks for the help.

1 Like

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