I’m trying to make a door system ran by a module script, so If I ever need to make edits, I only have to change one script. I’m using proximity prompts to open the door, it is detected by a script inside of the door which also checks if the player has clearance to open that specific door. After it checks the clearance, it requires the module from replicated storage and runs the function. I use script.Parent from the perspective of the script it is required from, but it doesn’t work.
Detection script inside of the door:
debounce = false
script.Parent.GuiPart1.Open.Triggered:Connect(function(player)
if debounce == false then
debounce = true
local playerClearance = player.Clearance.Value
local playerTeam = player.Team.Name
if script.Parent.Config.Clearance:FindFirstChild(playerClearance).Value == true or script.Parent.Config.Team:FindFirstChild(playerTeam).Value == true then
local module = require(game.ReplicatedStorage.Modules.DoorModule)
module.openSwingDoor1()
end
wait(script.Parent.Config.OpenTime.Value + 1)
debounce = false
end
end)
script.Parent.GuiPart2.Open.Triggered:Connect(function(player)
if debounce == false then
debounce = true
local playerClearance = player.Clearance.Value
local playerTeam = player.Team.Name
if script.Parent.Config.Clearance:FindFirstChild(playerClearance).Value == true or script.Parent.Config.Team:FindFirstChild(playerTeam).Value == true then
local module = require(game.ReplicatedStorage.Modules.DoorModule)
module.openSwingDoor2()
end
wait(script.Parent.Config.OpenTime.Value + 1)
debounce = false
end
end)
This is the module script:
local module = {}
module.openSwingDoor1 = function()
repeat
wait()
until script.Parent:FindFirstChild("Config")
wait()
script.Parent.GuiPart1.Open.Enabled = false
script.Parent.GuiPart2.Open.Enabled = false
script.Parent.CR1.LightPart.Color = Color3.fromRGB(39, 186, 5)
script.Parent.CR2.LightPart.Color = Color3.fromRGB(39, 186, 5)
tweenService = game:GetService("TweenService")
primaryPart = script.Parent.Door.PrimaryPart
CF = Instance.new("CFrameValue")
CF.Value = script.Parent.Door.PrimaryPart.CFrame
CF.Changed:Connect(function()
primaryPart.CFrame = CF.Value
end)
local TurnValue
local TurnBackValue
TurnValue = 130
TurnBackValue = -130
local tween = tweenService:Create(CF, TweenInfo.new(2,Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Value = primaryPart.CFrame * CFrame.Angles(math.rad(0),math.rad(TurnValue),math.rad(0))}):Play()
script.Parent.AudioPart.OpenFX:Play()
wait(script.Parent.Config.OpenTime.Value)
local tween = tweenService:Create(CF, TweenInfo.new(2,Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Value = primaryPart.CFrame * CFrame.Angles(math.rad(0),math.rad(TurnBackValue),math.rad(0))}):Play()
wait(0.8)
script.Parent.AudioPart.CloseFX:Play()
script.Parent.CR1.LightPart.Color = Color3.fromRGB(255, 89, 89)
script.Parent.CR2.LightPart.Color = Color3.fromRGB(255, 89, 89)
wait(0.1)
script.Parent.GuiPart1.Open.Enabled = true
script.Parent.GuiPart2.Open.Enabled = true
end
module.openSwingDoor2 = function()
repeat
wait()
until script.Parent:FindFirstChild("Config")
wait()
script.Parent.GuiPart1.Open.Enabled = false
script.Parent.GuiPart2.Open.Enabled = false
script.Parent.CR1.LightPart.Color = Color3.fromRGB(39, 186, 5)
script.Parent.CR2.LightPart.Color = Color3.fromRGB(39, 186, 5)
tweenService = game:GetService("TweenService")
primaryPart = script.Parent.Door.PrimaryPart
CF = Instance.new("CFrameValue")
CF.Value = script.Parent.Door.PrimaryPart.CFrame
CF.Changed:Connect(function()
primaryPart.CFrame = CF.Value
end)
local TurnValue
local TurnBackValue
TurnValue = -130
TurnBackValue = 130
local tween = tweenService:Create(CF, TweenInfo.new(2,Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Value = primaryPart.CFrame * CFrame.Angles(math.rad(0),math.rad(TurnValue),math.rad(0))}):Play()
script.Parent.AudioPart.OpenFX:Play()
wait(script.Parent.Config.OpenTime.Value)
local tween = tweenService:Create(CF, TweenInfo.new(2,Enum.EasingStyle.Quart, Enum.EasingDirection.Out), {Value = primaryPart.CFrame * CFrame.Angles(math.rad(0),math.rad(TurnBackValue),math.rad(0))}):Play()
wait(0.8)
script.Parent.AudioPart.CloseFX:Play()
script.Parent.CR1.LightPart.Color = Color3.fromRGB(255, 89, 89)
script.Parent.CR2.LightPart.Color = Color3.fromRGB(255, 89, 89)
wait(0.1)
script.Parent.GuiPart1.Open.Enabled = true
script.Parent.GuiPart2.Open.Enabled = true
end
return module
“CR” stands for CardReader.
“GuiPart” is the part which has the proximitypromt inside.
Thanks a lot, any replies would help!
Cosmo