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

How to stop Guis from layering?

So I have a script that opens a gui ontouch, however, if you touch it again after 2 seconds, it opens up another gui and layers up. I need a way to resolve this. Thanks =^)

debounce = true
script.Parent.Touched:connect(function(hit)
	
local hum = hit.Parent:FindFirstChild("Humanoid")
if hum ~= nil and debounce == true then
debounce = false

local player = game.Players:FindFirstChild(hum.Parent.Name)
local Gui = script.Parent.FrameWork:clone()
Gui.Parent = player.PlayerGui
wait(1)

debounce = true

end
end)

1 answer

✓ Accepted answer

Hey Skepticlemon,

There's a very simple way to do what I believe you are asking for. If I am not mistaken, you're asking how to make it to where another Gui doesn't clone to your PlayerGui, if you already have that Gui in there. Well, all you have to do for this is make use of the not operator and :FindFirstChild() function. You have to check if that object is not in the PlayerGui in that if statement that you have, so if you don't mind, I'm going to copy your script and make an enhancement of sorts where the script will check if the object is there before-hand or not. And if it is there, then it won't let the script run any farther.

####Enhancement Script

local debounce = true

script.Parent.Touched:connect(function(hit)
	local hum = hit.Parent:FindFirstChild("Humanoid")

	if hum ~= nil and debounce == true then

		local player = game.Players:FindFirstChild(hum.Parent.Name)
		if not player.PlayerGui:FindFirstChild("FrameWork") then -- Checks if the object 'FrameWork' is really inside of the PlayerGui. If it's not then it will pass the if statement.
			debounce = false
			local Gui = script.Parent.FrameWork:clone()
			Gui.Parent = player.PlayerGui
			wait(1)
			debounce = true
		end
	end
end)

##Well, I hope I helped and have a wonder day/night.

~~ KingLoneCat

1 comment

0

Works! Cheers.

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