I've got a simple click detector door. What I want to happen is that on contact with the "enemy" the door will activate and open. Currently when I run the script it does nothing and has no error message appear in the output. Any advice on how to fix this is appreciated! Here's the code that's located in a model with three other parts inside. The door part has a clickdetector, two boolvalues inside that are named "Open" and "Close", and one sound.

local door = script.Parent.Door
local FRef = script.Parent.FRef
local FRef2 = script.Parent.FRef2

local debounce = false
script.Parent.door.Touched:connect(function(p)
	if debounce == true then return end
	debounce = true
	if door.Close.Value == true and p.Parent.Name == "Enemy" then
		script.Parent.Door.Audio2:Play()
		door.CFrame = FRef2.CFrame
		door.Orientation = Vector3.new(0, 0, 0)
		door.Close.Value = false
		door.Open.Value = true

	else if door.Open.Value == true and p.Parent.Name == "Enemy" then
			script.Parent.Door.Audio2:Play()
			door.CFrame = FRef.CFrame
			door.Orientation = Vector3.new(0, -90, 0)
			door.Close.Value = true
			door.Open.Value = false
		end
	end
	wait(3)
	debounce = false
end)

2 comments

0

Is your enemy named Enemy?

0

yup it is