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

How to make dissapper on touch?

Asked by
22To 70
9 years ago

ok so i want when they touch the part it dissappers then after it waits 20 it reappers?

Heres what i tried im not that good with scripting

while true do
    onTouch()
     part.Brick.Transperancy = 0
    wait(20)
end

2 answers

Log in to vote
2
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
9 years ago

You need to use the Touched event to detect when an object is touched! You also want to check if it's a player! One last thing, there is no need for a loop! Just use a debounce.

debounce = false

script.Parent.Touched:connect(function(hit) -- Goes directly into the part
    if hit.Parent and game.Players:GetPlayerFromCharacter() and debounce == false then
        debounce = true
        script.Parent.Transparency = 1 -- 1 is invisible!
        wait(20)
        debounce = false
        script.Parent.Transparency = 0
    end
end)
Ad
Log in to vote
0
Answered by 9 years ago

You need to define a function.


function onTouch() script.Parent:Destroy() wait(20) end script.Parent.Touched:connect(onTouch)

also, use Destroy(). Transparency just makes it invisible.

Hope this helped.

-ds

0
He also wanted it to reappear, don't forget that! Shawnyg 4330 — 9y
0
Sorry. ChemicalHex 979 — 9y

Answer this question