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

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

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!

1 comment

0

Why do you have two ends? You only need one. Also, please format your code from now on...

5 answers

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. 

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 :)

simple!


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

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)

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.

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