I was having an issue with my door before but it got fixed (Cframe script error message - #3 by JmPopYT) I am now working on my game once again as I had some irl stuff I was busy with. I am duplicating the doors so I can finish the hallway for the building I am creating. When I click E to open a door it now opens a different door. I am not sure what the issue is as I am not a scripter.
This is how the model/script looks in the explorer tab:
This is the script:
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(0.5,0,0))
wait(0.1)
end
wait(1)
for i = 1, 7 do
doorModel:PivotTo(doorModel.PrimaryPart.CFrame + Vector3.new(0.5,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)
Yes, they’re all named “Door”. How would I go about defining them using the scripts parent? Before I duplicated them the doors did work. I would use CollectionService but I have no clue how to change the script to set that up
Right now you are getting the door by game.workspace.Door, but every door is named “Door.” Thus, your error of it opening only a singular door. Doing script.Parent to find the door would be better because it gets that specific door.
When I change “game.workspace.Door” to script.Parent and test out the script it gives me this error: DoorModel is not a valid member of Model “Workspace.Door”
I tried “parent.DoorHitbox.DoorModel” and it is still opening another door. Also, I never fully made the script, the parts that I made was all broken and didn’t work. I had to make a devforum post to get help about fixing it which got A door to work now that I have multiple it isn’t working anymore.
local parent = script.Parent
local child = script.Parent.DoorHitbox.ProximityPrompt
local doorHitbox = script.Parent.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(0.5,0,0))
wait(0.1)
end
wait(1)
for i = 1, 7 do
doorModel:PivotTo(doorModel.PrimaryPart.CFrame + Vector3.new(0.5,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)
Just replaced it and it seems to be working. What is the main difference with the replacement other then to make the script shorter? Or is that the only difference?
If the door isn’t open the CanCollide should be on which is by default, once the door is open all the parts including the “DoorHitbox” should go CanCollide false so people can walk through the door once its open