Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

2 comments

0

What's the wait() for?

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.

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.