Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Sensor = script.Parent.Sensor -- Reference to the sensor part
- local LeftDoor = script.Parent.L -- Reference to the left door model
- local RightDoor = script.Parent.R -- Reference to the right door model
- local Config = require(script.Parent.Configuration) -- Require the Configuration module
- local LED = script.Parent.MainFrame.LED.Light -- Reference to the LED Light
- -- Reference the Open and Closed positions inside the L and R models
- local OpenPositionL = LeftDoor.Open.Position -- Reference to the "Open" part inside L
- local OpenPositionR = RightDoor.Open.Position -- Reference to the "Open" part inside R
- local ClosedPositionL = LeftDoor.Closed.Position -- Reference to the "Closed" part inside L
- local ClosedPositionR = RightDoor.Closed.Position -- Reference to the "Closed" part inside R
- local DoorLocked = false
- local StopLight = script.Parent.StopandGo.Red
- local GreenLight = script.Parent.StopandGo.Green
- local TweenService = game:GetService("TweenService")
- -- Function to set the LED color
- local function setLEDColor(r, g, b)
- LED.Color = Color3.fromRGB(r, g, b)
- end
- -- Function to move Frame and Glass parts to their target position with configurable tween parameters
- local function movePartsToPosition(doorModel, targetPosition, duration, easingStyle, glassOffset)
- -- Loop through the Frame and Glass parts
- for _, part in ipairs(doorModel:GetChildren()) do
- local targetPos
- if part.Name == "Glass" then
- -- Apply the glass offset based on the door's state (open or closed)
- targetPos = targetPosition + glassOffset
- else
- targetPos = targetPosition
- end
- -- Create a tween with configurable duration and easing style
- local tweenInfo = TweenInfo.new(duration, easingStyle)
- local tween = TweenService:Create(part, tweenInfo, {Position = targetPos})
- tween:Play()
- end
- end
- -- Function to close the doors by moving parts to the Closed position
- local function closeDoors(duration, easingStyle)
- setLEDColor(255, 0, 4) -- Set LED color to red when closing
- movePartsToPosition(LeftDoor, ClosedPositionL, duration, easingStyle, Config.DoorConfig.LeftGlassClosedOffset)
- movePartsToPosition(RightDoor, ClosedPositionR, duration, easingStyle, Config.DoorConfig.RightGlassClosedOffset)
- end
- -- Function to open the doors by moving parts to the Open position
- local function openDoors(duration, easingStyle)
- if DoorLocked == true then
- return
- end
- setLEDColor(0, 255, 0) -- Set LED color to green when opening
- movePartsToPosition(LeftDoor, OpenPositionL, duration, easingStyle, Config.DoorConfig.LeftGlassOpenOffset)
- movePartsToPosition(RightDoor, OpenPositionR, duration, easingStyle, Config.DoorConfig.RightGlassOpenOffset)
- -- Wait for the configured hold time before closing the doors
- wait(Config.DoorConfig.HoldTime)
- -- Close the doors by moving them back to the Closed position
- closeDoors(duration, easingStyle)
- end
- script.Parent.StopandGo.ClickRed.ClickDetector.MouseClick:Connect(function(player)
- if player:GetRankInGroup(Config.RankRequirements.GroupId) >= Config.RankRequirements.MinRankId then
- DoorLocked = true
- closeDoors(Config.DoorConfig.OpenTime, Config.DoorConfig.EasingStyle)
- StopLight.Color = Color3.fromRGB(255, 0, 0)
- GreenLight.Color = Color3.fromRGB(9, 85, 5)
- script.Parent.StopandGo.Screen.SurfaceGui.Enabled = true
- end
- end)
- script.Parent.StopandGo.ClickGreen.ClickDetector.MouseClick:Connect(function(player)
- if player:GetRankInGroup(Config.RankRequirements.GroupId) >= Config.RankRequirements.MinRankId then
- DoorLocked = false
- StopLight.Color = Color3.fromRGB(66, 0, 0)
- GreenLight.Color = Color3.fromRGB(26, 255, 14)
- script.Parent.StopandGo.Screen.SurfaceGui.Enabled = false
- end
- end)
- -- Connect the Touched event to detect player interaction
- Sensor.Touched:Connect(function(hit)
- local character = hit.Parent
- local player = game.Players:GetPlayerFromCharacter(character)
- if player then
- -- Use the configuration parameters directly from Config
- local tweenDuration = Config.DoorConfig.OpenTime -- Use OpenTime directly
- local tweenEasingStyle = Config.DoorConfig.EasingStyle -- Use EasingStyle directly
- openDoors(tweenDuration, tweenEasingStyle)
- else
- print("Non-player object touched the sensor")
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement