CFrame door has a spasm

Howdy howdy, my door script has recently started to malfunction. Every now and then when opening the door, it has a spasm for no reason. This has nothing to do with collisions, as I have tried turning them off. Here is a video of it.

Here’s my script.

for _,unlocked in pairs(game.Workspace.Doors.Unlocked:GetChildren()) do
	local Can = true
	local prompt = unlocked.Prompt.ProximityPrompt
	local prompt2 = unlocked.Prompt2.ProximityPrompt
	local hinge = unlocked.Hinge
	Open = false
	prompt.Enabled = true
	prompt2.Enabled = true
	
	
	prompt.Triggered:Connect(function(player)
		if prompt.ActionText == "Open Door" and prompt2.ActionText == "Open Door" then
			Open = true
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Close Door"
			prompt2.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = unlocked.PrimaryPart.CFrame:lerp(finish1,i)
				unlocked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
			wait(5)
			if prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" then
				prompt.Enabled = false
				prompt2.Enabled = false
				prompt.ActionText = "Open Door"
				prompt2.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,0.7,.1 do
					local cfm = unlocked.PrimaryPart.CFrame:lerp(finish2,i)
					unlocked:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" then
				Open = false
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Open Door"
			prompt2.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,0.7,.1 do
					local cfm = unlocked.PrimaryPart.CFrame:lerp(finish,i)
					unlocked:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
		end
	end)
	
	
	prompt2.Triggered:Connect(function(player)
		if prompt2.ActionText == "Open Door" and prompt.ActionText == "Open Door" then
			Open = true
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Close Door"
			prompt.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = unlocked.PrimaryPart.CFrame:lerp(finish1,i)
				unlocked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
			wait(5)
			if prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" then
				prompt2.Enabled = false
				prompt.Enabled = false
				prompt2.ActionText = "Open Door"
				prompt.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,0.7,.1 do
					local cfm = unlocked.PrimaryPart.CFrame:lerp(finish2,i)
					unlocked:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" then
			Open = false
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Open Door"
			prompt.ActionText = "Open Door"
			hinge.Closing:Play()
			local finish = unlocked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = unlocked.PrimaryPart.CFrame:lerp(finish,i)
				unlocked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
		end
	end)
end

--locked

for _,locked in pairs(game.Workspace.Doors.Locked:GetChildren()) do
local Can = true
	local prompt = locked.Prompt.ProximityPrompt
	local prompt2 = locked.Prompt2.ProximityPrompt
local hinge = locked.Hinge
Open = false
prompt.Enabled = true
local group = locked.Value.Value

	prompt.Triggered:Connect(function(player)
		if prompt.ActionText == "Open Door" and prompt2.ActionText == "Open Door" and player:IsInGroup(group) then
			Open = true
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Close Door"
			prompt2.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = locked.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
			for i = 0,7,.1 do
				local cfm = locked.PrimaryPart.CFrame:lerp(finish1,i)
				locked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
			wait(5)
			if prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" then
				prompt.Enabled = false
				prompt2.Enabled = false
				prompt.ActionText = "Open Door"
				prompt2.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = locked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,0.7,.1 do
					local cfm = locked.PrimaryPart.CFrame:lerp(finish2,i)
					locked:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" and player:IsInGroup(group) then
			Open = false
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Open Door"
			prompt2.ActionText = "Open Door"
			hinge.Closing:Play()
			local finish = locked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = locked.PrimaryPart.CFrame:lerp(finish,i)
				locked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
		end
	end)


	prompt2.Triggered:Connect(function(player)
		if prompt2.ActionText == "Open Door" and prompt.ActionText == "Open Door" and player:IsInGroup(group) then
			Open = true
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Close Door"
			prompt.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = locked.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = locked.PrimaryPart.CFrame:lerp(finish1,i)
				locked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
			wait(5)
			if prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" then
				prompt2.Enabled = false
				prompt.Enabled = false
				prompt2.ActionText = "Open Door"
				prompt.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = locked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
				for i = 0,0.7,.1 do
					local cfm = locked.PrimaryPart.CFrame:lerp(finish2,i)
					locked:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" and player:IsInGroup(group) then
			Open = false
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Open Door"
			prompt.ActionText = "Open Door"
			hinge.Closing:Play()
			local finish = locked.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(90),0)
			for i = 0,0.7,.1 do
				local cfm = locked.PrimaryPart.CFrame:lerp(finish,i)
				locked:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
		end
	end)
end


--garage


for _,garage in pairs(game.Workspace.Doors.Garage:GetChildren()) do
	local Can = true
	local prompt = garage.Prompt.ProximityPrompt
	local prompt2 = garage.Prompt2.ProximityPrompt
	local hinge = garage.Hinge
	Open = false
	prompt.Enabled = true
	local group = garage.Value.Value

	prompt.Triggered:Connect(function(player)
		if prompt.ActionText == "Open Door" and prompt2.ActionText == "Open Door" and player:IsInGroup(group) then
			Open = true
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Close Door"
			prompt2.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = garage.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(85),0)
			for i = 0,0.7,.005 do
				local cfm = garage.PrimaryPart.CFrame:lerp(finish1,i)
				garage:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
			wait(10)
			if prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" then
				prompt.Enabled = false
				prompt2.Enabled = false
				prompt.ActionText = "Open Door"
				prompt2.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = garage.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(85),0)
				for i = 0,0.7,.005 do
					local cfm = garage.PrimaryPart.CFrame:lerp(finish2,i)
					garage:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt.ActionText == "Close Door" and prompt2.ActionText == "Close Door" and player:IsInGroup(group) then
			Open = false
			prompt.Enabled = false
			prompt2.Enabled = false
			prompt.ActionText = "Open Door"
			prompt2.ActionText = "Open Door"
			hinge.Closing:Play()
			local finish = garage.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(85),0)
			for i = 0,0.7,.005 do
				local cfm = garage.PrimaryPart.CFrame:lerp(finish,i)
				garage:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt.Enabled = true
			prompt2.Enabled = true
		end
	end)


	prompt2.Triggered:Connect(function(player)
		if prompt2.ActionText == "Open Door" and prompt.ActionText == "Open Door" and player:IsInGroup(group) then
			Open = true
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Close Door"
			prompt.ActionText = "Close Door"
			hinge.Opening:Play()
			local finish1 = garage.PrimaryPart.CFrame*CFrame.Angles(0,math.rad(85),0)
			for i = 0,0.7,.005 do
				local cfm = garage.PrimaryPart.CFrame:lerp(finish1,i)
				garage:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
			wait(10)
			if prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" then
				prompt2.Enabled = false
				prompt.Enabled = false
				prompt2.ActionText = "Open Door"
				prompt.ActionText = "Open Door"
				hinge.Closing:Play()
				local finish2 = garage.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(85),0)
				for i = 0,0.7,.005 do
					local cfm = garage.PrimaryPart.CFrame:lerp(finish2,i)
					garage:SetPrimaryPartCFrame(cfm)
					wait()
				end
				wait(0.4)
				prompt.Enabled = true
				prompt2.Enabled = true
			end
		elseif prompt2.ActionText == "Close Door" and prompt.ActionText == "Close Door" and player:IsInGroup(group) then
			Open = false
			prompt2.Enabled = false
			prompt.Enabled = false
			prompt2.ActionText = "Open Door"
			prompt.ActionText = "Open Door"
			hinge.Closing:Play()
			local finish = garage.PrimaryPart.CFrame*CFrame.Angles(0,-math.rad(85),0)
			for i = 0,0.7,.005 do
				local cfm = garage.PrimaryPart.CFrame:lerp(finish,i)
				garage:SetPrimaryPartCFrame(cfm)
				wait()
			end
			wait(0.4)
			prompt2.Enabled = true
			prompt.Enabled = true
		end
	end)
end
1 Like

You should be using a tween for things like this. Most cosmetic effects you’d be doing via for loops like this are intended to be done via tweens. Tweens also give you more control over the easing style and speed of these “animations”, on top of being shorter to write and more performant.

Since it’d be a bit too difficult to explain exactly how to set things up, I’ve taken the liberty of recreating the entire door system.

DoorSystem.rbxl (43.6 KB)

All you need is to put a part in the “Doors” folder, make sure it has a “Hinge” part as a child (this will be where the door rotates relative to). You can also add an “OpenAngle” attribute to the door in order to tell it what rotation, in degrees, it should have when open (set to -90 degrees in this example).

The script itself is in ServerScriptService, feel free to look into it. It should be very straight forward and easy to modify.

1 Like

That’s great, however every other door system that I have tried does not work with doors with multiple parts, at least not for me. This is also one of those door systems. Modifying my own script into a tweenservice script also doesn’t work.

It should, can you pass me the model of the door you’re using? I’ll rewrite the script a tiny bit for it to work with multiple part doors

dor.rbxm (5.5 KB)

Do you mind if I tweak the model a bit to make it easier to add doors in the future for your project? Or is your project too far in development where it wouldn’t make sense to replace every single door?

It would be fine to tweak it, I’m not too far into development.

1 Like

If you want to learn how to tween models you should look at this post,

It’s pretty easy to follow and he explains a lot of necessary things

1 Like

DoorSystem2.rbxl (46.8 KB)

Here you go! As long as parts are children of the doors, they’ll be considered as part of the door assembly and will move along with the rest of the door.

Edit: Small mistake, forgot to replace “Open Door” text with “Close Door” but it should be really easy to fix.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.