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

How to prevent multiple ScreenGui's from showing up and overlapping?

I have a script that opens up a ScreenGui from within a part. It acts as a dialog box like in an rpg. But if the part is clicked again when the dialog box is currently open, then another will show up and overlap the previous one. Is there a way to prevent this?

Here's what I have.

local waitfor = false
local waittime = 5 

script.Parent.ClickDetector.MouseClick:connect(function(p)
	script.Disabled = false 
	local t = {}
	local g = script.Parent:GetChildren()
		for i = 1,#g do 
		if g[i]:IsA("ScreenGui") then 
			table.insert(t,#t+1,g[i]:Clone())
		end 
	end 
	for i = 1,#t do 
	t[i].Parent = p.PlayerGui
end 
	wait(3)
	script.Disabled = false 
		if waitfor == true then 
		wait(waittime-3)
			for i = 1,#t do 
			t[i]:Destroy()
		end 
	end 
end)

2 answers

✓ Accepted answer
local waitfor = false
local waittime = 5 
local active = false
script.Parent.ClickDetector.MouseClick:connect(function(p)
	if active == false then
active = true
    script.Disabled = false 
    local t = {}
    local g = script.Parent:GetChildren()
        for i = 1,#g do 
        if g[i]:IsA("ScreenGui") then 
            table.insert(t,#t+1,g[i]:Clone())
        end 
    end 
    for i = 1,#t do 
    t[i].Parent = p.PlayerGui
end 
    wait(3)
    script.Disabled = false 
        if waitfor == true then 
        wait(waittime-3)
            for i = 1,#t do 
            t[i]:Destroy()
active = false
        end 
	end
    end 
end)

I believe this should work(I cannot test it at this moment) All I did was add

local active = false



if active == false then
active = true
end



active = false

What it should do, is check if active is false, if it's false it starts. If it isn't, it doesn't.

I am unable to test this right now, please let me know if it works.

2 comments

0

It worked! Thank you so much!

0

No problem! Glad to help. If you need anymore help, don't be afraid to ask. You can DM me on Discord @ EdwardMacGimsey#3206 if you need anymore help I'll respond asap

try this

Try using if p.PlayerGui:FindFirstChild("GUINAME") then
	-- code here to clone Gui
end

3 comments

0

Woops i ment

0

I meant if p.PlayerGui:FindFirstChild("GUINAME") then -- code here to clone Gui end

0

That was supposed to replace line 9, right? If yes, then it didn't fix the problem.

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