-- Door variables
local Door = script.Parent.Parent.Door.Door
local DoorLogo = Door.DoorLogo
local DoorSeg = Door.DoorSegment
Door.PrimaryPart = Door.DoorSegment
local Open, ShouldBe = false, false
local InZone = {}
-- Door moving function
function Move(O)
DoorLogo.Moving:Play()
for i = 1, 58 do
wait(0.01)
-- Changes the door cframe position.
local X, Y, Z = DoorSeg.CFrame.X, DoorSeg.CFrame.Y, DoorSeg.CFrame.Z
Door:SetPrimaryPartCFrame(DoorSeg.CFrame * CFrame.new((O and -0.1 or 0.1),0,0))
end
DoorLogo.Moving:Stop()
DoorLogo.Closed:Play()
end
-- Door parts flashing function
function Flash(Colour)
if Colour == nil then return end
for i = 1,2 do
for i,v in pairs(workspace.SecurityDoor.Door.Door:GetChildren()) do
if v.Name == "scpl" then
wait(0.3)
v.BrickColor = BrickColor.new(Colour)
wait(0.3)
v.BrickColor = BrickColor.new("Medium stone grey")
end
end
end
end
-- Detect player within zone and flash parts
local sensor = script.Parent.Parent.Door.Sensor
while wait() do
local shouldOpen = false
for _, Player in pairs(game.Players:GetPlayers()) do
if game.Players.LocalPlayer.TeamColor ~= game.Teams["Class-D"].TeamColor or game.Players.LocalPlayer.TeamColor ~= game.Teams["Class-E"].TeamColor then
if (Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and (Player.Character.HumanoidRootPart.Position - sensor.Position).magnitude < 10) then
shouldOpen = true
break
end
end
end
-- Flash parts
if shouldOpen and not Open then
Open = true
DoorLogo.Beep:Play()
Flash("Bright green")
Move(true)
elseif not shouldOpen and Open then
Open = false
Move(false)
DoorLogo.Beep:Play()
Flash("Bright red")
end
end
✓ ANSWER ACCEPTED
This script is only working inside the studio it is not a localscript. Any help?
1 answer
✓ Accepted answer
Try running it on "Test" -> Local Server, you should be able to distinguish the problem there. Most scripts tend to load differently on an actual server because of the delay time a script takes to load.
For your variables I suggest using:
local Door = script.Parent.Parent.Door:WaitForChild("Door")
local DoorLogo = Door:WaitForChild("DoorLogo ")
local DoorSeg = Door:WaitForChild("DoorSegment ")
As it properly loads the objects used before the script actually runs, problems like this may occur because the script may load faster than the object itself therefor running even without the object thus causing an error.
This discussion is preserved as it was. New answers, comments, and votes are closed.
