Does anyone have experience reusing Gui menus? Should I try it?

I have a simple Yes/No gui. I’m going to need it for many instances in my game, ex entering a car, picking up an item, turning on a light…
I could either create a new frame and buttons for each instance, or have one gui that is referenced by all of the scripts.
Has anyone tried this before? How has it worked and was it worth it? I just don’t see it being practical to make a new gui for nearly 50 different choices. But then again, the scripts might interfere with each other causing 2 to activate from one button push etc…

1 Like

It won’t be a problem if you script it correctly. Making a new UI for each instance would be the wrong way to do it. Your idea is correct.

I’ve done some thinking/experimenting and I’ve run into a form of the issue I predicted. I use objectX.ClickDetector.MouseClick:Connect(function(plr) to make the choice GUI appear. If they click “No” when interacting with object X, I can make the Gui disappear but the script will still be listening for the Yes/No button push. I’m not sure what to do. If I disconnect() the script when they push “No”, the player won’t be able to interact with object X in the future. But if I don’t disconnect it, it activates when it isn’t supposed to.

I somehow can’t find any tutorials on how to do this despite it seeming like a common thing to need.

What do you mean by “it’s still listening for a yes/no push”? You need to provide an example.

It’s difficult for me to describe. Here’s my code

local debounceList = {}
local nobebounce = false

script.Parent.MouseClick:Connect(function(plr)
	plr.PlayerGui.CurrentChoice.Value = 17
	local function typewriter(s)
		local newstring

		for i = 0, s:len(), 1 do
			newstring = s:sub(1, i)
			plr.PlayerGui.dialogueoption.Frame.TextLabel.Text = newstring
			wait(.05)
		end
	end
	if not debounceList[plr] then
		debounceList[plr] = true
		plr.dialogueoptionGUIstatus.Value = plr.dialogueoptionGUIstatus.Value + 1
		typewriter("A couple red gems lay on a cloth. Gather them?")
		local yesbutton = plr.PlayerGui.dialogueoption.Frame.yesbutton
		local nobutton = plr.PlayerGui.dialogueoption.Frame.nobutton
		yesbutton.MouseButton1Up:Connect(function()
			if plr.PlayerGui.CurrentChoice.Value == 17 then
				if script:GetAttribute("Done") == "yes" then
					typewriter("Someone else is currently interacting with this.")
					wait(3)
					plr.dialogueoptionGUIstatus.Value = plr.dialogueoptionGUIstatus.Value - 1
					debounceList[plr] = false
				else
					script:SetAttribute("Done","yes")
					plr.dialogueoptionGUIstatus.Value = plr.dialogueoptionGUIstatus.Value - 1
					game.ReplicatedStorage.gemsplayer.Value = plr.Name
					game.ReplicatedStorage.Gems:FireAllClients()
					for _, Players in pairs(game.Players:GetChildren()) do
						local characters = workspace[Players.Name]
						if not characters:FindFirstChild("Red Gems") then
							game.ServerStorage["Red Gems"]:Clone().Parent = characters
						end
					end	

					script.Parent:Destroy()
				end
			else
				plr.dialogueoptionGUIstatus.Value = plr.dialogueoptionGUIstatus.Value - 1
				debounceList[plr] = false
			end


		end)
		nobutton.MouseButton1Up:Connect(function()
			if nobebounce == false then
				nobebounce = true
				plr.dialogueoptionGUIstatus.Value = plr.dialogueoptionGUIstatus.Value - 1
				wait(1)
				debounceList[plr] = false
				nobebounce = false
				print("check3")
			end
		end)
	end
end)

This is code to pick up a red gem. When the player clicks on the gem, the gui is made visible. When the player clicks “no”, the gui is made invisible (by adding/subtracting 1 from the Guistatus.Value, which is within the player). When the player goes over to pick up another item, say a spear, the gui reappears (by adding 1 to the Value). And if the player clicks “no”, 2 points are subtracted from the Status Value. One point from the gem script and one point from the spear script. Because they were both waiting for the player to push yes/no.

I hope that makes sense because that’s my dilemma.

1 Like

I’ve reused a loading screen gui once for a game that i’ve worked on. While someone did find out that the text in the loading screen was misleading (the text being “welcome to y!” despite the game name being “x”), there wasn’t any effect on the game after all so yes you should try it! (Just don’t overuse it)

Yeah its not really practical to use it since front page games also tend to reuse guis (example: pet simulator x,bubble gum simulator and ect)