If you step on a certain part, it will transfer a ScreenGui into the PlayerGui. It works fine, but it causes about 5 other clones of that same Gui to show up as well. It can be pretty messy, so I'd like to fix it. There are no error messages, and I use FilteringEnabled.
local menu = script.Parent.CharacterGui local function onTouched(hit) if (game.Players:GetPlayerFromCharacter(hit.Parent)) then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player.PlayerGui:findFirstChild("menu") then menu:Clone().Parent = player.PlayerGui wait() end end end script.Parent.Touched:connect(onTouched)
A debounce is used to prevent something that is is activated a lot or can be.(i.e)
game.Workspace.Button.Touched:connect(function(hit) print("Button pressed") --Print the message wait(1) --Wait for 1 second print("Hi :D") --Print another message end)
Since the player would touch the part quite a bit it would make the output spammed with messages. Most of the time debounces are used in functions and if statements. Learn more at Debounce
The way I'd do it is insert a boolvalue inside the gui,And if it's set to true(Which is set when you clone it the first time) Then it doesn't clone and just prints 'already cloned' or something similiar
Something like this:
if yourGUI:FindFirstChild("ClonedOrNot").Value == true then print("Already Cloned GUI") else --do script here end