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

How to prevent multiple Guis from showing up onTouch?

Asked by
snarns 25
7 years ago

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)
0
you should just have the gui in the playergui already and update a couple of things depending on the touch button RubenKan 3615 — 7y
0
I suppose that could be an option. I'll give it a try, thanks for the idea. snarns 25 — 7y
0
._. Do you even frickin read the answers you are given. farrizbb 465 — 7y
0
Yes. They didn't help and I figured it out on my own. snarns 25 — 7y

2 answers

Log in to vote
0
Answered by
farrizbb 465 Moderation Voter
7 years ago
Edited 7 years ago

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

0
The example you gave doesn't implement debounce. That's the wiki's example on an instance where debounce should be implemented. ScriptGuider 5640 — 7y
0
I did show him how to implement it but i was told to remove it :/ . farrizbb 465 — 7y
0
also if he reads the wiki he'll learn how to farrizbb 465 — 7y
Ad
Log in to vote
0
Answered by
VoltCode 101
7 years ago

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

Answer this question