Advertisement
ur9rgi

RTS - FlowMasterV1 I Modelscript

Sep 29th, 2024 (edited)
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 KB | None | 0 0
  1. local Sensor = script.Parent.Sensor -- Reference to the sensor part
  2. local LeftDoor = script.Parent.L -- Reference to the left door model
  3. local RightDoor = script.Parent.R -- Reference to the right door model
  4.  
  5. local Config = require(script.Parent.Configuration) -- Require the Configuration module
  6. local LED = script.Parent.MainFrame.LED.Light -- Reference to the LED Light
  7.  
  8. -- Reference the Open and Closed positions inside the L and R models
  9. local OpenPositionL = LeftDoor.Open.Position -- Reference to the "Open" part inside L
  10. local OpenPositionR = RightDoor.Open.Position -- Reference to the "Open" part inside R
  11. local ClosedPositionL = LeftDoor.Closed.Position -- Reference to the "Closed" part inside L
  12. local ClosedPositionR = RightDoor.Closed.Position -- Reference to the "Closed" part inside R
  13.  
  14. local DoorLocked = false
  15. local StopLight = script.Parent.StopandGo.Red
  16. local GreenLight = script.Parent.StopandGo.Green
  17.  
  18. local TweenService = game:GetService("TweenService")
  19.  
  20. -- Function to set the LED color
  21. local function setLEDColor(r, g, b)
  22.     LED.Color = Color3.fromRGB(r, g, b)
  23. end
  24.  
  25.  
  26. -- Function to move Frame and Glass parts to their target position with configurable tween parameters
  27. local function movePartsToPosition(doorModel, targetPosition, duration, easingStyle, glassOffset)
  28.     -- Loop through the Frame and Glass parts
  29.     for _, part in ipairs(doorModel:GetChildren()) do
  30.         local targetPos
  31.  
  32.         if part.Name == "Glass" then
  33.             -- Apply the glass offset based on the door's state (open or closed)
  34.             targetPos = targetPosition + glassOffset
  35.         else
  36.             targetPos = targetPosition
  37.         end
  38.  
  39.         -- Create a tween with configurable duration and easing style
  40.         local tweenInfo = TweenInfo.new(duration, easingStyle)
  41.         local tween = TweenService:Create(part, tweenInfo, {Position = targetPos})
  42.         tween:Play()
  43.     end
  44. end
  45.  
  46. -- Function to close the doors by moving parts to the Closed position
  47. local function closeDoors(duration, easingStyle)
  48.     setLEDColor(255, 0, 4) -- Set LED color to red when closing
  49.     movePartsToPosition(LeftDoor, ClosedPositionL, duration, easingStyle, Config.DoorConfig.LeftGlassClosedOffset)
  50.     movePartsToPosition(RightDoor, ClosedPositionR, duration, easingStyle, Config.DoorConfig.RightGlassClosedOffset)
  51. end
  52.  
  53. -- Function to open the doors by moving parts to the Open position
  54. local function openDoors(duration, easingStyle)
  55.     if DoorLocked == true then
  56.         return
  57.     end
  58.     setLEDColor(0, 255, 0) -- Set LED color to green when opening
  59.     movePartsToPosition(LeftDoor, OpenPositionL, duration, easingStyle, Config.DoorConfig.LeftGlassOpenOffset)
  60.     movePartsToPosition(RightDoor, OpenPositionR, duration, easingStyle, Config.DoorConfig.RightGlassOpenOffset)
  61.  
  62.     -- Wait for the configured hold time before closing the doors
  63.     wait(Config.DoorConfig.HoldTime)
  64.  
  65.     -- Close the doors by moving them back to the Closed position
  66.     closeDoors(duration, easingStyle)
  67. end
  68.  
  69.  
  70. script.Parent.StopandGo.ClickRed.ClickDetector.MouseClick:Connect(function(player)
  71.     if player:GetRankInGroup(Config.RankRequirements.GroupId) >= Config.RankRequirements.MinRankId then
  72.         DoorLocked = true
  73.         closeDoors(Config.DoorConfig.OpenTime, Config.DoorConfig.EasingStyle)
  74.         StopLight.Color = Color3.fromRGB(255, 0, 0)
  75.         GreenLight.Color = Color3.fromRGB(9, 85, 5)
  76.         script.Parent.StopandGo.Screen.SurfaceGui.Enabled = true
  77.     end
  78. end)
  79.  
  80. script.Parent.StopandGo.ClickGreen.ClickDetector.MouseClick:Connect(function(player)
  81.     if player:GetRankInGroup(Config.RankRequirements.GroupId) >= Config.RankRequirements.MinRankId then
  82.         DoorLocked = false
  83.         StopLight.Color = Color3.fromRGB(66, 0, 0)
  84.         GreenLight.Color = Color3.fromRGB(26, 255, 14)
  85.         script.Parent.StopandGo.Screen.SurfaceGui.Enabled = false
  86.     end
  87. end)
  88.  
  89.  
  90.  
  91. -- Connect the Touched event to detect player interaction
  92. Sensor.Touched:Connect(function(hit)
  93.     local character = hit.Parent
  94.     local player = game.Players:GetPlayerFromCharacter(character)
  95.     if player then
  96.  
  97.         -- Use the configuration parameters directly from Config
  98.         local tweenDuration = Config.DoorConfig.OpenTime -- Use OpenTime directly
  99.         local tweenEasingStyle = Config.DoorConfig.EasingStyle -- Use EasingStyle directly
  100.  
  101.         openDoors(tweenDuration, tweenEasingStyle)
  102.     else
  103.         print("Non-player object touched the sensor")
  104.     end
  105. end)
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement