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

Why won't the Touched event execute?

I'm trying to make a door that makes all the parts in it so their CanCollide property is false. I tested it out, but it won't work. The error also doesn't show up in the output. Here's the script:

door = script.parent.parent
frame = door.Frame
framewindow = door.FrameWindow
framewindow2 = door.FrameWindow2
pane = door.Pane

function opendoor()
	frame.CanCollide = false
	framewindow.CanCollide = false
	framewindow2.CanCollide = false
	pane.CanCollide = false
	frame.Doorbell:Play() -- Oh yea, this part plays an audio on Touched.
	
end

frame.Touched:connect(opendoor)

Anyone have a solution? I feel like the Output is failing me.

2 answers

✓ Accepted answer

Well, I found one problem on line 1; you need to change it to script.Parent.Parent. Other than that, I don't see any script-breaking errors. I would also advise changing those ugly global variables into local variables, like so:

local door = script.Parent.Parent
local frame = door.Frame
local framewindow = door.FrameWindow
local framewindow2 = door.FrameWindow2
local pane = door.Pane

local function opendoor()
    frame.CanCollide = false
    framewindow.CanCollide = false
    framewindow2.CanCollide = false
    pane.CanCollide = false
    frame.Doorbell:Play() -- Oh yea, this part plays an audio on Touched.

end

frame.Touched:connect(opendoor)

It won't make much difference for something like this, but it's good practice.

1 comment

0

Thanks.

I don't really suggest using numbers inside variables or names of objects if you are going to script them, however this may solve your issue:

door = script.Parent.Parent
frame = door.Frame
local frameWindow = door.FrameWindow
local frameWindowTwo = door["FrameWindow2"]
pane = door.Pane

function opendoor()
    frame.CanCollide = false
    frameWindow.CanCollide = false
    frameWindowTwo.CanCollide = false
    pane.CanCollide = false
    frame.Doorbell:Play() -- Oh yea, this part plays an audio on Touched.

end

frame.Touched:connect(opendoor)

I also suggest making sure that everything is case sensitive.

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