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

How to prevent multiple Guis from showing up onTouch?

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)

4 comments

0

you should just have the gui in the playergui already and update a couple of things depending on the touch button

0

I suppose that could be an option. I'll give it a try, thanks for the idea.

0

._. Do you even frickin read the answers you are given.

0

Yes. They didn't help and I figured it out on my own.

2 answers

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

3 comments

0

The example you gave doesn't implement debounce. That's the wiki's example on an instance where debounce should be implemented.

0

I did show him how to implement it but i was told to remove it :/ .

0

also if he reads the wiki he'll learn how to

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

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