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)