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:
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)
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)
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)
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.
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)