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:

local function onTouch(hit)
    modelOfBricks = game.Workspace.Model
    nameOfBricks = "Porto"
    for i,v in pairs(modelOfBricks:GetChildren()) do
        if v.Name == nameOfBricks then
            v.Transparency = 0
            v.CanCollide = true
        end
    end
end

.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.

local function onTouch(hit)
    modelOfBricks = game.Workspace.Model
    nameOfBricks = "Porto"
    for i,v in pairs(modelOfBricks:GetChildren()) do
        if v.Name == nameOfBricks then
            v.Transparency = 0
            v.CanCollide = true
        end
    end
    wait()
    script.Parent:Destroy() -- Once everthing has ran, just Destroy the part.
end

script.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
local function onTouch(part)
  if part.Parent.Name == "Humanoid"
    script.Parent:Destroy()
  end

script.Parent.Touched:connect(onTouch)

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

Answer this question