Door script not working

Hello, I am trying to make an animated door that opens when the player touches a part, but when I touch the part, the script doesn’t run. Heeres the script:

local frame = script.Parent




local model = frame.Parent
local frameClose = model:WaitForChild("Door")
local frameOpen = model:WaitForChild("DoorOpen")
local opened = model:WaitForChild("Opened")
local tweenService = game:GetService("TweenService")

local debounce = true
function onTouched(hit) -- when touched
	if hit.Parent.Humanoid~= nil then
		if debounce == true then
			debounce = false
			if opened.Value == true then
				opened.Value = false


				tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameClose.CFrame}):Play()
			else
				opened.Value = true


				tweenService:Create(frame,TweenInfo.new(.35),{CFrame = frameOpen.CFrame}):Play()
			end

			wait(.35)
			debounce = true
		end
	end
end

script.Parent.Parent.Trigger:connect(onTouched) -- Should fire function

	

NOTE: I am not using a click detector, I am using a part that is being touched.

Does anyone know what I’m doing wrong?

1 Like

what is script.Parent.Parent.Trigger?

1 Like

I think you mean

script.Parent.Parent.Touched:Connect(onTouched)
2 Likes