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

Why wont door change when touched? (New Scripter here!)

Heya guys, im a brand new scripter and i wanted to try to code a simple door. Here is my code:

local part = game.Workspace.Part

function OnTouched()

part.Transparency = 0.5
part.CanCollide = false
wait(1.8)
part.Transparency = 1
part.CanCollide = true

end

For whatever reason, whenever i touch the part, (It is named Part in the workspace) nothing happens, why is this?

2 answers

✓ Accepted answer

Did you connect a Touched event? Here's how it works:

local part = game.Workspace.Part -- Define "part" variable as the part in the Workspace

function OnTouched() -- Function we want to execute when something touches that part
	part.Transparency = 0.5
	part.CanCollide = false
	wait(1.8)
	part.Transparency = 1
	part.CanCollide = true
end

part.Touched:Connect(OnTouched) -- The OnTouched function will be executed once the Touched event from that part is fired

2 comments

0

Thanks! It makes so much sense now!

0

you're welcome c:

Try using .Touched event

local part = script.Parent

script.Parent.Touched:Connect(function()-- detects touch
	part.Transparency = 0.5
	part.CanCollide = false
	wait(1.8)
	part.Transparency = 1
	part.CanCollide = true
end)

put script in part

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