Cframe script error message

I have a script that when you click E (ProximityPrompt) the door will use Cframe to move to the right and after a few seconds, it will move back. It works on a part but then when I drag the script into the actual door and change the script up a bit to attempt to get it to work but I am not sure why it isn’t working.

Error message: CFrame is not a valid member of Model “Workspace.Door.DoorHitbox.DoorModel”

Explorer:
image

Script:

local parent = script.Parent
local child = script.Parent.DoorHitbox.ProximityPrompt
local door = game.Workspace.Door.DoorHitbox.DoorModel

local function onTriggered(player)
	child.Enabled = false
	for i = 1, 7 do
		door.CFrame = door.CFrame - Vector3.new(1, 0, 0)
		wait(0.1)
	end
	wait(4)
	for i = 1, 7 do
		door.CFrame = door.CFrame + Vector3.new(1, 0, 0)
		wait(0.1)
	end
	child.Enabled = true
end

child.Triggered:Connect(onTriggered)
1 Like

Hi, :wave:

instead of door.CFrame = …

use,

door:PivotTo(door.CFrame + Vector3.new(1,0,0))

and also set the PrimaryPart to a part.

:slight_smile:

1 Like

Do I replace:
“door.CFrame = door.CFrame - Vector3.new(1, 0, 0)”
&
“door.CFrame = door.CFrame + Vector3.new(1, 0, 0)”

with your script?
“door:PivotTo(door.CFrame + Vector3.new(1,0,0))”

yep.

And also change the primarypart to DoorHitbox

1 Like

When I do that I get an error message saying:
CFrame is not a valid member of Model "Workspace.Door.DoorHitbox.DoorModel"

Script:

local parent = script.Parent
local child = script.Parent.DoorHitbox.ProximityPrompt
local door = game.Workspace.Door.DoorHitbox.DoorModel

local function onTriggered(player)
	child.Enabled = false
	for i = 1, 7 do
		door:PivotTo(door.CFrame - Vector3.new(1,0,0))
		wait(0.1)
	end
	wait(4)
	for i = 1, 7 do
		door:PivotTo(door.CFrame + Vector3.new(1,0,0))
		wait(0.1)
	end
	child.Enabled = true
end

child.Triggered:Connect(onTriggered)

My bad, instead of door.CFrame
use,

door.PrimaryPart.CFrame
1 Like

I’m still getting an error message and it says "Workspace.Door.Script:8: attempt to index nil with 'CFrame'"

I’m not sure if I replaced the right “door.CFrame” ?

local parent = script.Parent
local child = script.Parent.DoorHitbox.ProximityPrompt
local door = game.Workspace.Door.DoorHitbox.DoorModel

local function onTriggered(player)
	child.Enabled = false
	for i = 1, 7 do
		door:PivotTo(door.PrimaryPart.CFrame - Vector3.new(1,0,0))
		wait(0.1)
	end
	wait(4)
	for i = 1, 7 do
		door:PivotTo(door.PrimaryPart.CFrame + Vector3.new(1,0,0))
		wait(0.1)
	end
	child.Enabled = true
end

child.Triggered:Connect(onTriggered)

Did you set the primary part of door model?

1 Like

I have it like this:
image

Select the “Door” and change the PrimaryPart of it to the “DoorHitbox” so its not nil

1 Like

Not in this instance, select the DoorModel and set the primary part to one of the 5 parts

1 Like

yeah my bad, i didnt read the script right

1 Like

Error message: Workspace.Door.Script:8: attempt to index nil with 'CFrame'

I have set the Door’s PrimaryPart to the “DoorHitbox”

select the DoorModel and set the primary part to one of the 5 parts

1 Like

Alright, my bad. Select the “DoorModel” and set the primarypart to any part inside it.

1 Like

It seems to be working now. Thank you owee and Pop.

1 Like

Np, be sure to ask for more help in the future if you need it! :smiley:

If I have multiple doors it will be fine if I have the same layout or do I have to change something? The doors are gonna be hallway doors so there’s gonna be a lot of doors.

Sorry for asking so many questions I just wanna make sure it wont break anything script related.

I’m sure it won’t bother the scripts if you have multiple ones because the script is running for the one that it’s located in.

1 Like

Sorry to bother you again. If you have a second you could look over this script and let me know if it’s good or not that would be amazing. I made it so that when the door is open CanCollide gets set to false. The script works and does exactly that. I am just wondering if it’s written well or not because it looks very long and complicated for what it’s actually doing.

local parent = script.Parent
local child = script.Parent.DoorHitbox.ProximityPrompt
local doorHitbox = game.Workspace.Door.DoorHitbox
local doorModel = doorHitbox.DoorModel

local function onTriggered(player)
	child.Enabled = false
	for _, part in ipairs(doorHitbox:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CanCollide = false
		end
	end
	for _, part in ipairs(doorModel:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CanCollide = false
		end
	end
	for _, part in ipairs(parent:GetChildren()) do
		if part:IsA("BasePart") then
			part.CanCollide = false
		end
	end
	for i = 1, 7 do
		doorModel:PivotTo(doorModel.PrimaryPart.CFrame - Vector3.new(1,0,0))
		wait(0.1)
	end
	wait(4)
	for i = 1, 7 do
		doorModel:PivotTo(doorModel.PrimaryPart.CFrame + Vector3.new(1,0,0))
		wait(0.1)
	end
	for _, part in ipairs(doorHitbox:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CanCollide = true
		end
	end
	for _, part in ipairs(doorModel:GetDescendants()) do
		if part:IsA("BasePart") then
			part.CanCollide = true
		end
	end
	for _, part in ipairs(parent:GetChildren()) do
		if part:IsA("BasePart") then
			part.CanCollide = true
		end
	end
	child.Enabled = true
end

child.Triggered:Connect(onTriggered)