Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isn't my GUI popup script working correctly?

I'm trying to make a GUI that pops up when you click a part, but I don't want people to get tons of GUI's from clicking it over and over again. To fix this, I made a script which detects if the player already has the gui, but it isn't working. The script keeps coming back thinking that I still have the UI in my PlayerGui. This is the script:

local gui = script.Parent.MainframeGui

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
		if  Player.PlayerGui:FindFirstChild("MainframeGui")  ==  nil then
		local gui = script.Parent.MainframeGui:Clone()
		gui.Parent = Player.PlayerGui
		gui.TimeRemaining.LocalScript.Disabled = false
	else
			print("Player already has the UI")
	end
end)

Any help would be appreciated! Thank you, have a great day and stay healthy! :)

1 comment

0

I was using a LocalScripot inside of the GUI to destroy the GUI, this means it was only on the client. I ended up using a remote event from a LocalScript in the GUI to destroy it. Thank you :)

1 answer

You have to use the player argument which is already built into the event. Also, you had two gui variables, which were probably overwriting each other.

local gui = script.Parent:WaitForChild("MainframeGui")

script.Parent.ClickDetector.MouseClick:Connect(function(player)
	if player:WaitForChild("PlayerGui"):FindFirstChild("MainframeGui")  ==  nil then
		local guiClone = gui:Clone()
		guiClone.Parent = player:WaitForChild("PlayerGui")
		guiClone:WaitForChild("TimeRemaining"):WaitForChild("LocalScript").Disabled = false   
	else
		print("Player already has the UI")
	end
end)

2 comments

0

Whoops, sorry. I forgot to clarify that this script is inside of a part, which is how you get the gui to show up. It's basically a click to get gui script inside a part.

0

I edited it, so it should work now.

This discussion is preserved as it was. New answers, comments, and votes are closed.