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

How do you make a block disappear two seconds after you touch it?

Asked by 10 years ago

I have tried making a block disappear after two seconds by what I know, this is what I came up with:

function onTouch()

game.Workspace.Part.Transparency = 0.5
wait(2)
game.Workspace.Part.CanCollide = false
game.Workspace.Part.Transparency = 1
    end
end

connect:OnTouch()

I tried to test it by playing solo, but it didn't respond for more than ten minutes! Is this a problem with Roblox or did my script crash the game? Please help!

0
Why do you have two ends? You only need one. Also, please format your code from now on... NoahWillCode 370 — 10y

5 answers

Log in to vote
1
Answered by 10 years ago

First, let's put you code in a code block and tab it correctly.

function onTouch()
    game.Workspace.Part.Transparency = 0.5 
    wait(2) 
    game.Workspace.Part.CanCollide = false 
    game.Workspace.Part.Transparency = 1
    end 
end

connect:OnTouch()

You have too many ends. Your connection line is completely messed up. You don't have a debounce, so it will be all glitchy. Try this:

local debounce = false
function onTouch()
    if debounce == false then
        debounce = true
        game.Workspace.Part.Transparency = 0.5 
        wait(2) 
        game.Workspace.Part.CanCollide = false 
        game.Workspace.Part.Transparency = 1
        debounce = false
    end
end

script.Parent.Touched:connect(onTouch) --We connect the touched event to the onTouch function. 
Ad
Log in to vote
0
Answered by
Wiscript 622 Moderation Voter
8 years ago

Pretty easy I must say

Here's the code

local function Disappear(hit)
    local hum = hit.Parent:FindFirstChild("Humanoid")
    if hum then
        script.Parent.Transparency = 0.25
        wait(0.5)
        script.Parent.Transparency = 0.50
        wait(0.5)
        script.Parent.Transparency = 0.75
        wait(0.5)
        script.Parent:Remove()
    end
end
script.Parent.Touched:connect(Disappear)

Accept my answer if it works :)

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

simple!


``function onTouched(hit) wait(2) script.Parent:Destroy() end

Log in to vote
-1
Answered by 10 years ago

Here

function onTouch()
game.Workspace.Part.Transparency = 0.5
wait(2)
game.Workspace.Part.CanCollide = false
game.Workspace.Part.Transparency = 1
end

script.Parent.Touched:connect(onTouch)
Log in to vote
-1
Answered by
iLegitus 130
10 years ago

Here is a nice and simple code.

script.Parent.Touched:connect(function(hit)
wait(0.03)
    script.Parent.Transparency = 0.9
    script.Parent.Transparency = 0.8
    script.Parent.Transparency = 0.7
    script.Parent.Transparency = 0.6
    script.Parent.Transparency = 0.5
    script.Parent.Transparency = 0.4
    script.Parent.Transparency = 0.3
    script.Parent.Transparency = 0.2
    script.Parent.Transparency = 0.1
    script.Parent.Transparency = 0

print("Brick Sucessfully Dissapeared")

Hope it helped.

Answer this question