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

How to remove a button immediately after touching it? [ANSWERED]

Asked by 8 years ago
Edited 8 years ago

So, I made a button, then I put this into it:

01local function onTouch(hit)
02    modelOfBricks = game.Workspace.Model
03    nameOfBricks = "Porto"
04    for i,v in pairs(modelOfBricks:GetChildren()) do
05        if v.Name == nameOfBricks then
06            v.Transparency = 0
07            v.CanCollide = true
08        end
09    end
10end
11 
12.Parent.Touched:connect(onTouch)

Now I can't figure out how to make this button disappear immediately after being touched.

EDIT: Answered by rexbit, many thanks to her.

2 answers

Log in to vote
0
Answered by
rexbit 707 Moderation Voter
8 years ago
Edited 8 years ago

Just add a :Destroy.

01local function onTouch(hit)
02    modelOfBricks = game.Workspace.Model
03    nameOfBricks = "Porto"
04    for i,v in pairs(modelOfBricks:GetChildren()) do
05        if v.Name == nameOfBricks then
06            v.Transparency = 0
07            v.CanCollide = true
08        end
09    end
10    wait()
11    script.Parent:Destroy() -- Once everthing has ran, just Destroy the part.
12end
13 
14script.Parent.Touched:connect(onTouch)
0
What's the wait() for? Overscores 381 — 8y
0
The wait isn't necessary, I add it just to keep things in order. If that's your reason to downvote then think twice, this script works, I just added a wait to keep it organized. rexbit 707 — 8y
Ad
Log in to vote
0
Answered by 8 years ago
Edited 8 years ago
1local function onTouch(part)
2  if part.Parent.Name == "Humanoid"
3    script.Parent:Destroy()
4  end
5 
6script.Parent.Touched:connect(onTouch)

I think that work, I don't know since I can't test now, hope it helps.

Answer this question