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

Help stop making a GUI show up multiple times on touch?

Asked by
snarns 25
6 years ago

So if the player touches a certain part, a GUI within that part will show up. This works fine, but the GUI will clone and overlap itself many times when I only want one of it. I tried adding debounce but then it somehow only works once, and wont show up again if the player restarts. (I use FE btw) How can I fix this problem?

local menu = script.Parent.Animations

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)

1 answer

Log in to vote
0
Answered by 6 years ago

I may be wrong, but from what I can see, it's just the fact you placed the wrong name of the GUI.

local menu = script.Parent.Animations

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)

The menu variable shows that the GUI is named 'Animations', but you're checking for a GUI named 'menu'.

Therefore, you should just change the line to if not player.PlayerGui:FindFirstChild("Animations") then.

I apologise in advance if I got this wrong.

0
I've played around with it, and somehow if I change that line then the GUI wont work after I've reset my character. Weird. Thanks for trying though :) snarns 25 — 6y
Ad

Answer this question