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

How to make disappearing block when touched?

Hey I am currently making a disappearing block when touched but I can’t seem to realize what’s wrong with my script... can someone help me? Please?

local block = script.Parent
local debounce = true 

block:Connect(function(hit)
       local humanoid = hit.Parent:FindFirstChildWhichIsA(‘Humanoid’)
       if humanoid and debounce == true then
            debounce = false
             block.Transparency = 0.5
             wait(1)
             block.Transparency = 1
             block.CanCollide = false
             wait(3)
             block.Transparency = 0
             block.CanCollide = true
             debounce = true
  end)

2 answers

✓ Accepted answer

Add .touched to connect to the Touched event.


local block = script.Parent
local debounce = true 

block.Touched:Connect(function(hit)
       local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
       if humanoid and debounce == true then
            debounce = false
             block.Transparency = 0.5
             wait(1)
             block.Transparency = 1
             block.CanCollide = false
             wait(3)
             block.Transparency = 0
             block.CanCollide = true
             debounce = true
  end)

4 comments

0

Where?

0

I did it for you, just copy the script lol

0

Also, I added it to the block:Connect() to make block.Touched:Connect()

0

Oh! Thanks you so much!

Howdy!

You're not correctly firing the function you need. You need to refer to an actual event for the function to fire. Functions are like guns, you need to pull the trigger to fire it. Here, you don't have a trigger.

Try this.

local block = script.Parent
local debounce = true 

block.Touched:Connect(function(hit)
       local humanoid = hit.Parent:FindFirstChildWhichIsA(‘Humanoid’)
       if humanoid and debounce == true then
            debounce = false
             block.Transparency = 0.5
             wait(1)
             block.Transparency = 1
             block.CanCollide = false
             wait(3)
             block.Transparency = 0
             block.CanCollide = true
             debounce = true
  end)

If this helped you out, consider accepting this answer for those sweet, sweet reputation points. If not, comment below and I (or someone else) will help you out.

Be sure to check out the Roblox API Documentation as well for additional reference.

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