GUI not responding after character respawn

The issue I’m having is that the GUI menus I’ve made work perfectly until the player dies and respawns. Before they respawn, if a GUI button is activated to open a menu, I have the associated script blur the screen and then move the menu into view from below the screen area (moving from a scale of 1.5 on the Y axis to 0.5 on the Y axis since the menu’s main frame is set to be anchored at 0.5 on the Y axis as well). I know the script is working otherwise because, after respawning, the screen will still blur, but the menu does not move into view.

I use module scripts to achieve the majority of my game’s functionality and the GUI is no different. Specifically, I use a ModuleScript to handle opening and closing any menu by indicating which frame is to be tweened into view, as described above.

Let me make sure that I’m clear about this: all of my GUI in the StarterGUI is set NOT to ResetOnSpawn. I say this because it would seem the most likely and easiest solution, but making sure it’s false, setting it to true, or even just toggling it on/off has not resolved the issue.

Other things I’ve tried:

  • I’ve tried using a LocalScript for each menu’s open and closing both in the PlayerScripts and directly parented to the GUI
  • I’ve tried setting the script to run its main functions again on humanoid.Died/wait for character to ensure the script runs again on respawn
  • I’ve placed the GUI in the ReplcatedStorage and had the GUI clone itself into the PlayerGui on character added

None of that has worked and I’m sure I’ve tried some other, smaller things that I’m forgetting now.

I’ve done a ton of looking around and possible solutions found both here in the official forums as well as elsewhere, but none of the solutions seem to work for me. My setup is pretty long, but I’m going to give both the menu button script and the Gui manager script (that handles the opening and closing functionality). A couple of things to know: each menu is a ScreenGui located in a folder called “Menus” inside of the StarterGui service. The main Frame for each menu is called “Border”. On beginning play, any module scripts with an Initialize function have that function called, then any scripts with the Initiate function have that function called. This ensures proper loading order of needed references, etc. Any events within the Initiate function behave as though you load up an event listener for any time it’s fired. For example, button.Activated is set up in the below script so that any time the button is activated, the connected function is called.

MenuButtonsManager - A ModuleScript located in StarterPlayerScripts>Client>Gui

--!strict
--[[ Services ]]--
local Players = game:GetService("Players")
local StarterPlayer = game:GetService("StarterPlayer")
local TweenService = game: GetService("TweenService")

--[[ Variables ]]--
-- player and menu GUI references
local player = Players.LocalPlayer
local Gui = player.PlayerGui
local MenuButtons = Gui:WaitForChild("MenuButtons")

--[[ Required ]]--
local Manager = require(StarterPlayer.StarterPlayerScripts.Client.GuiManager)

-- Referencing each menu GUI
local MenuFrames = Gui.Menus:GetChildren()

-- Setting TweenInfo for mouse hover effect
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

-- Menus and MenuButtons
local buttons = {}
local menus = {}

-- Audio
local Audio = StarterPlayer.StarterPlayerScripts.Audio
local Click = Audio.Click


--[[ Functions ]]--
-- Hover Effects
-- On mouse hovering over the button, the button tweens inward and the button text appears
local function HoverEffectStart(button)
	local TweenTextIn = TweenService:Create(button.TextLabel, tweenInfo, {TextTransparency = 0, TextStrokeTransparency = 0})
	local TweenButtonIn = TweenService:Create(button, tweenInfo, {Position = UDim2.new(-0.3, 0, 0.5, 0)})
	TweenTextIn:Play()
	TweenButtonIn:Play()
end


-- On mouse no longer hovering over the button, the button tweens back out and the button text disappears
local function HoverEffectEnd(button)
	local TweenTextOut = TweenService:Create(button.TextLabel, tweenInfo, {TextTransparency = 1, TextStrokeTransparency = 1})
	local TweenButtonOut = TweenService:Create(button, tweenInfo, {Position = UDim2.new(-0.63, 0, 0.5, 0)})
	TweenTextOut:Play()
	TweenButtonOut:Play()
end


return {

	Initialize = function()
		for _, button in pairs(MenuButtons:GetDescendants()) do
			if not button:IsA("ImageButton") then continue end
			if button.Name == "MenuButton" then
				table.insert(buttons, button)		
			end
		end

		for _, menu in MenuFrames do
			if not menu.Border then continue end
			menus[menu.Name] = menu.Border
		end
	end,


	Initiate = function()
		-- Loop through the buttons on the left to play hover effect and open/close the selected GUI
		for _, button in pairs(buttons) do
			button.MouseEnter:Connect(function()
				HoverEffectStart(button)
			end)

			button.MouseLeave:Connect(function()
				HoverEffectEnd(button)
			end)

			button.Activated:Connect(function()
				Click:Play()
				local open = nil
				for _, menu in menus do
					if menu.visible then open = menu end
				end
				Manager.OpenMenu(menus[button.Parent.Name], open)
			end)
		end
	end,

}

GuiManager - A ModuleScript located in StarterPlayerScripts>Client

--!strict
--[[ Services ]]--
local TweenService = game: GetService("TweenService")

--[[ Variables ]]--
-- opened and closed positions
local openPos = UDim2.new(0.5, 0, 0.5, 0)
local closePos = UDim2.new(0.5, 0, 1.5, 0)

-- Setting TweenInfo for (un)blurring the screen for when a menu is closed/opened
local tweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tweenOpenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Back, Enum.EasingDirection.Out)
local tweenCloseInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.In)

local SharedFunctions = {}

--[[ Functions ]]--
-- Close the given menu, checking if the screen needs to be unblurred when doing so
SharedFunctions.CloseMenu = function(menu: Frame, unblur: boolean)
	if menu.Visible then
		--move the menu out of view
		local closeTween = TweenService:Create(menu, tweenCloseInfo, {Position = closePos})
		closeTween:Play()
		task.wait(0.5)
		-- once off the screen, disable the menu's visibility
		menu.Visible = false

		if unblur then
			-- unblur the background
			local blurTween = TweenService:Create(game.Lighting.Blur, tweenInfo, {["Size"] = 0})
			blurTween:Play()
		end
	end
end


-- Open the given menu, optional openMenu parameter to close any other open menu first
SharedFunctions.OpenMenu = function(menu: Frame, openMenu: Frame?)
	-- open the passed in menu
	if not menu.Visible then
		-- close the currently open menu if any
		if openMenu then
			if openMenu.Visible then
				SharedFunctions.CloseMenu(openMenu, false)
				task.wait(0.25)
			end
		end
		
		-- blur the background
		local blurTween = TweenService:Create(game.Lighting.Blur, tweenInfo, {["Size"] = 24})
		blurTween:Play()
		-- make the menu visible
		menu.Visible = true
		--move the menu into view
		local openTween = TweenService:Create(menu, tweenOpenInfo, {Position = openPos})
		openTween:Play()
	else
		-- if the menu is open, close it
		SharedFunctions.CloseMenu(menu, true)
	end
end

return SharedFunctions

I hope someone can help me figure this out. I really don’t want to have to restructure my entire setup just for this issue, but the player not being able to access any menus in the game if they die is a pretty serious issue.

It turns out, having GUI inside of a folder screws up any scripts that reference them once the character respawns. The fix is to apparently not be able to organize your GUI into folders and have it all sitting in the StarterGui service directly.

Seems I just had to post this to come up with a solution.

3 Likes

Further reading and reasoning (because this engine does dumb things sometimes, like having Gui reset on spawn regardless of setting if it’s in a folder):

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