Doors/Windows are not moving, and are instead throwing an error

Hello guys, so I need help with this problem right there. When I click the “doors down” button, I get an error instead of the doors/windows going down. Here is a video:


Here are the scripts involved:
Doors Script:

local rs = game:GetService("ReplicatedStorage")
local tweens = game:GetService("TweenService")
local event = rs.cubicleDoorControl
local RCS = require(rs.RoundControlStorage)
local doorDown = game.Workspace.doorDown

local downYPosition = 1520.844
local upYPosition = 1540.594

event.OnServerEvent:Connect(function()
	local doors = RCS.Doors
	
	if doorDown.Value == false then
		for _, door in pairs(doors) do
			local downCFrame = door.CFrame
			downCFrame.Y = downYPosition
			tweens:Create(door, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {["CFrame"] = downCFrame}):Play()
		end 
	elseif doorDown.Value == true then
		for _, door in pairs(doors) do
			local upCFrame = door.CFrame
			upCFrame.Y = upYPosition
			tweens:Create(door, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {["CFrame"] = upCFrame}):Play()
		end 
	end
end)

Button Script:

local rs = game:GetService("ReplicatedStorage")
local event = rs.cubicleDoorControl
local button = script.Parent
local defaultText = button.Text
local doorDown = game.Workspace.doorDown

script.Parent.MouseButton1Up:Connect(function()
	event:FireServer()

	if doorDown.Value == false then
		doorDown.Value = true
	elseif doorDown.Value == true then
		doorDown.Value = false
	end

	local debounce = 3
	
	while debounce ~= 0 do
		button.Text = tostring(debounce)
		debounce -= 1
		task.wait(1)
	end
	
	button.Text = defaultText
end)

Modulescript:

local RCS = {}
local cubicles = game.Workspace.cubicles

RCS.V3s = {
	Vector3.new(105.656, 1540.594, 70.875),
	Vector3.new(105.656, 1540.594, 35.438),
	Vector3.new(35.437, 1540.594, 105.656),
	Vector3.new(70.875, 1540.594, 105.656),
	Vector3.new(105.656, 1540.594, -70.875),
	Vector3.new(105.656, 1540.594, -35.437),
	Vector3.new(-105.656, 1540.594, -35.438),
	Vector3.new(0, 1540.594, 105.656),
	Vector3.new(-35.438, 1540.594, 105.656),
	Vector3.new(-35.437, 1540.594, -105.656),
	Vector3.new(0, 1540.594, -105.656),
	Vector3.new(-105.656, 1540.594, 35.437),
	Vector3.new(-70.875, 1540.594, -105.656),
	Vector3.new(35.438, 1540.594, -105.656),
	Vector3.new(70.875, 1540.594, -105.656),
	Vector3.new(-105.656, 1540.594, -70.875),
	Vector3.new(-105.656, 1540.594, 70.875),
	Vector3.new(-70.875, 1540.594, 105.656)
}

RCS.Doors = {
	cubicles.cubicle1.cubicleWindow,
	cubicles.cubicle2.cubicleWindow,
	cubicles.cubicle3.cubicleWindow,
	cubicles.cubicle4.cubicleWindow,
	cubicles.cubicle5.cubicleWindow,
	cubicles.cubicle7.cubicleWindow,
	cubicles.cubicle8.cubicleWindow,
	cubicles.cubicle9.cubicleWindow,
	cubicles.cubicle10.cubicleWindow,
	cubicles.cubicle11.cubicleWindow,
	cubicles.cubicle12.cubicleWindow,
	cubicles.cubicle14.cubicleWindow,
	cubicles.cubicle15.cubicleWindow,
	cubicles.cubicle16.cubicleWindow,
	cubicles.cubicle17.cubicleWindow,
	cubicles.cubicle18.cubicleWindow,
	cubicles.cubicle19.cubicleWindow,
	cubicles.cubicle20.cubicleWindow
	}

return RCS

I would appreciate some help! Thanks!

You can’t write to a CFrame as it’s an immutable datatype, you’d need to reconstruct the CFrame as so:

local downCFrame = door.CFrame

local offsetCFrame = CFrame.new(downCFrame.Position.X, downYPosition, downCFrame.Position.Z) * downCFrame.Rotation

tweens:Create(door, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {["CFrame"] = offsetCFrame}):Play()

you’d need to do that for each time you’re writing to cframe.Y

Alternatively you could also just create the CFrames as common values at the top of your script and then tween to that, it might give you more optimal results that way (if you play one tween then the next before the previous is finished, you’d likely encounter the door being offset)

1 Like
if not doorDown.Value then
	for _, door in pairs(doors) do
		local downCFrame = door.CFrame.Position
		local newCFrame = CFrame.new(downCFrame.X, downYPosition, downCFrame.Z)
		tweens:Create(door, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = newCFrame}):Play()
	end 
else
	for _, door in pairs(doors) do
		local upCFrame = door.CFrame.Position
		local newCFrame = CFrame.new(upCFrame.X, upYPosition, upCFrame.Z)
		tweens:Create(door, TweenInfo.new(1.2, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut), {CFrame = newCFrame}):Play()
	end 
end
1 Like

If your doors are all the same height, then why not do:

local newCFrame = door.CFrame + Vector3.new(0, doorheight, 0)

Just showing you move a CFrame by using .new, as in new location.
This one upCFrame.Y … you can get the Y location from. It’s like read only.

Sorry, I didn’t mean to reply to you directly but to the OP

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