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

How to stop Guis from layering?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

0
Works! Cheers. Skepticlemon 24 — 6y
Ad

Answer this question