Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
snarns 25
7 years ago

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

Log in to vote
0
Answered by 7 years ago
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.

0
It worked! Thank you so much! snarns 25 — 7y
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 iEdwardii 22 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago

try this

Try using if p.PlayerGui:FindFirstChild("GUINAME") then
    -- code here to clone Gui
end
0
Woops i ment LastApollo 76 — 7y
0
I meant if p.PlayerGui:FindFirstChild("GUINAME") then -- code here to clone Gui end LastApollo 76 — 7y
0
That was supposed to replace line 9, right? If yes, then it didn't fix the problem. snarns 25 — 7y

Answer this question