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?
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
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