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()
1 | part.Transparency = 0.5 |
2 | part.CanCollide = false |
3 | wait( 1.8 ) |
4 | part.Transparency = 1 |
5 | part.CanCollide = true |
end
For whatever reason, whenever i touch the part, (It is named Part in the workspace) nothing happens, why is this?
Did you connect a Touched event? Here's how it works:
01 | local part = game.Workspace.Part -- Define "part" variable as the part in the Workspace |
02 |
03 | function OnTouched() -- Function we want to execute when something touches that part |
04 | part.Transparency = 0.5 |
05 | part.CanCollide = false |
06 | wait( 1.8 ) |
07 | part.Transparency = 1 |
08 | part.CanCollide = true |
09 | end |
10 |
11 | part.Touched:Connect(OnTouched) -- The OnTouched function will be executed once the Touched event from that part is fired |
Try using .Touched event
1 | local part = script.Parent |
2 |
3 | script.Parent.Touched:Connect( function () -- detects touch |
4 | part.Transparency = 0.5 |
5 | part.CanCollide = false |
6 | wait( 1.8 ) |
7 | part.Transparency = 1 |
8 | part.CanCollide = true |
9 | end ) |
put script in part