Ad
Log in to vote
0

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

Asked by
snarns 21
4 days 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)

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by 4 days 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 21 — 4d
Ad

Answer this question



Ad