Why wont my door open?

I don’t understand why my door isn’t working. I did the same exact script as I did with my other door. So basically when a person goes through my door, it opens for them, it worked for my other door, but for this door it isn’t. Can anyone help me? the center part is welded to the door, and the center part is anchored. I am not sure if the weld part is the other way around lol, prob is… here is my script

local TweenService = game:GetService("TweenService")

local center = game.Workspace.Door5.Center
local door = "closed"

local CF = Instance.new("CFrameValue")
CF.Value = center.CFrame
CF.Changed:Connect(function()
	center.CFrame = CF.Value
end)

local debounce = false
script.Parent.Detector.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
	end
	if debounce == true then return end
	debounce = true
	if door == "closed" then
		TweenService:Create(CF, TweenInfo.new(0.5,Enum.EasingStyle.Back,Enum.EasingDirection.Out),             {Value = center.CFrame * CFrame.Angles(math.rad(0), math.rad(-100), math.rad(0))}):Play()
		door = "open"
		wait(5)
		TweenService:Create(CF, TweenInfo.new(0.5,Enum.EasingStyle.Back,Enum.EasingDirection.Out),              {Value = center.CFrame * CFrame.Angles(math.rad(0), math.rad(100), math.rad(0))}):Play()
		door = "closed"
	end
	wait(1)
	debounce = false
end)

if you know why this is happening, please leave a comment.

1 Like

As far as I can tell, there is nothing wrong with the actual code aside from the the Humanoid check that does nothing.

Aka this part:

if hit.Parent:FindFirstChild("Humanoid") then
end

But that isn’t the issue. Can you open output and tell me if you see any errors?

I don’t really know whats the issue but, I think your statement which checks if the hit’s Parent has a Humanoid, should be wrapped around the rest of the code. Or simply return if its false.

script.Parent.Detector.Touched:Connect(function(hit)
	if not hit.Parent:FindFirstChild("Humanoid") then return end
	if debounce == true then return end

	debounce = true
	if door == "closed" then
		TweenService:Create(CF, TweenInfo.new(0.5,Enum.EasingStyle.Back,Enum.EasingDirection.Out),             {Value = center.CFrame * CFrame.Angles(math.rad(0), math.rad(-100), math.rad(0))}):Play()
		door = "open"
		wait(5)
		TweenService:Create(CF, TweenInfo.new(0.5,Enum.EasingStyle.Back,Enum.EasingDirection.Out),              {Value = center.CFrame * CFrame.Angles(math.rad(0), math.rad(100), math.rad(0))}):Play()
		door = "closed"
	end
	wait(1)
	debounce = false
end)

Would also recommend placing a print statement inside the Touched block to check till where its running.

I got no errors, I also did the print, and I did touch the detector but nothing happened with the tween… Here I will show you guys my workspace. help with door

the door is not anchored, the center part is… The detector is anchored as well. The weld constraint, has door as part0 and as part1 is center. I don’t know if those need to be switched around but I tried both ways.

ok I just fixed it, but my workspace is moving with it, do you know how to make it not do that LOL

Irrelevant to this topic, why don’t you use for i,v in pairs() and a module script it’s much easier and organized.

I am pretty new so do you mind showing me an example?

How does this matter?

I don’t know, maybe that if something was anchored that it could be the cause of the problem.

I fixed it but, when my door rotates, the floor does as well. Do you know how to fix this?

You are using “Center” to move the door?

yes, it’s my hinge. I set it as the primary part for the model. The parent of the model is workspace as well.

Try using corountines, like this:

local CF = Instance.new("CFrameValue")
CF.Parent = game:GetService("ReplicatedStorage")

local Changed = coroutine.wrap(function()
	center.CFrame = CF.Value
end)

CF.Changed:Connect(Changed)

My script worked on my other door and I am using the same script. Also, why would I need rep if I am not passing it on to another script or something.

Because CF didn’t have a parent, meaning it wasn’t created. And that’s probably the main reason for the script not to work.

I figured it out, I had a bunch of welds so that is why my door was making the floor move. Thanks for the help.

1 Like