Every time i touch the brick, the gui appears, but when i touch it again, it doesn't disappear, but clones it self again in the player gui. How can i make it where if i touch it it disappears instead of cloning itself even more? This script is in a regular script.
01 | script.Parent.Touched:connect( function (toucher) |
02 | local plr = game:GetService( "Players" ):GetPlayerFromCharacter(toucher.Parent) or game:GetService( "Players" ):GetPlayerFromCharacter(toucher.Parent.Parent) |
03 | if plr then |
04 | local help = game:GetService( "ReplicatedStorage" ):WaitForChild( "Intro" ) |
05 | help:Clone( 1 ).Parent = plr.PlayerGui |
06 | else |
07 | script.Parent.Touched:connect( function (awsomeness) |
08 | local plr = game:GetService( "Players" ):GetPlayerFromCharacter(awsomeness.Parent) or game( "Players" ):GetPlayerFromCharacter(awsomeness.Parent.Parent) |
09 | if plr then |
10 | local off = plr.PlayerGui:WaitForChild( "Intro" ) |
11 | off:Destroy() |
12 | end |
13 | end ) |
14 | end |
15 | end ) |
I would do it another way.
01 | local debounce = false --add this and call it whatever you want |
02 | --then add in your script a check |
03 | if plr and not debounce then |
04 | --lines to Clone that gui |
05 | debounce = true |
06 | --also add a wait() after this and write in brackets down the amount of seconds you need (the length of your Intro in secs, if it is a Intro and not a help gui) |
07 |
08 | --remove script.Parent.Touched:connect(function(awsomeness) as you already did that in the beginning so this is not needed |
09 | --remove 1 end) and 1 end from the end |
10 | --after that replace else with elseif and just do like I'll do down here |
11 | elseif plr and debounce then |
12 | local off = plr.PlayerGui:WaitForChild( 'Intro' ) |
13 | off:Destroy() --btw if this won't work then replace Destroy() with Remove() |
14 | debounce = false |
Or do you want to write the whole script down for you?