So, I have this Server Script and a folder called Doors in Workspace.
The Doors folder contains two folders, one called ExitDoors and another one called InsideDoors, both folders contain multiple models of doors, all of the models has a PrimaryPart assigned and all of its parts' CanCollide set to false. So it'd be: workspace.Doors.ExitDoors/InsideDoors
I also have a Neighbor team and Civilians team (more on that in a sec).
I've attempted to make Civilians team be able to open all doors with no problem, and Neighbor team be unable to open doors that are parented to ExitDoors.
For some reason, they eventually tend to just don't work anymore, no errors, Doors are just frozen, inactive...I'm really confused...
This is the script I've made:
local GeneralFunctions = require(workspace.GeneralFunctions) --Don't mind this.
local DefaultCFrames = {}
for _, doorsection in ipairs(script.Parent.Doors:GetChildren()) do
for _, door in ipairs(doorsection:GetChildren()) do
DefaultCFrames[door] = door.PrimaryPart.CFrame
end
end
local OpenDoorRange = 7
local SoundDebounce = {}
while true do
wait()
for _, doorsection in ipairs(script.Parent.Doors:GetChildren()) do
for _, door in ipairs(doorsection:GetChildren()) do
if DefaultCFrames[door] then
local Distance, Player = math.huge
-- Gets nearest player, you can skip this up to the for loop's end.
for _, plr in ipairs(game:GetService("Players"):GetPlayers()) do
if plr.Character and plr.Character:WaitForChild("Humanoid").Health > 0 then
local Distance_Alt = (
plr.Character:WaitForChild("HumanoidRootPart").Position -
(DefaultCFrames[door].Position - Vector3.new(0, door.PrimaryPart.Size.X / 2, 0) + Vector3.new(0, 2.31, 0))
).Magnitude
if Distance > Distance_Alt then Distance = Distance_Alt Player = plr end
end
end
local Sound
if Player ~= nil then
if (Player.Team == game:GetService("Teams").Civilians) or (Player.Team == game:GetService("Teams").Neighbor and door.Parent ~= script.Parent.Doors.ExitDoors) then
if Distance <= OpenDoorRange then
door:SetPrimaryPartCFrame(DefaultCFrames[door] * CFrame.Angles(math.rad(90), 0, 0))
if not SoundDebounce[door] then Sound = script.DoorOpen:Clone() SoundDebounce[door] = true end
else
door:SetPrimaryPartCFrame(DefaultCFrames[door])
if SoundDebounce[door] then Sound = script.DoorClose:Clone() SoundDebounce[door] = false end
end
end
end
if Sound then
Sound.Parent = door.PrimaryPart
Sound.PlaybackSpeed = Random.new():NextNumber(0.9, 1.1)
Sound.PlayOnRemove = true Sound:Destroy()
end
end
end
end
end
I really need help with this...Thanks for reading this.

3 comments
what even is this ;(
Don't use wait() as your loop's condition.
oh okay