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

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

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

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
0
Thanks! It makes so much sense now! SimplyBloo 27 — 4y
0
you're welcome c: arthurgps2 67 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Answer this question