Advertisement
ur9rgi

RTS - FlowMasterV1 I Serverscript

Sep 29th, 2024 (edited)
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.22 KB | None | 0 0
  1.  
  2. local Parcel = require(9428572121)
  3.  
  4. local placeOwnerID = game.CreatorId -- Gets the Place/Group Owner ID
  5. local ownerType = game.CreatorType -- Gets the type of owner (User or Group)
  6.  
  7. if Parcel:Whitelist("66f04a2e9e16e072651ae40f", "qeni590wrtn41hf2trmm9w4iht7q") then
  8.     if ownerType == Enum.CreatorType.Group then
  9.         warn("[RTS] License successfully active for group owner (Group ID: " .. placeOwnerID .. "). FlowMaster started.")
  10.     else
  11.         warn("[RTS] License successfully active for place owner (User ID: " .. placeOwnerID .. "). FlowMaster started.")
  12.     end
  13. else
  14.     if ownerType == Enum.CreatorType.Group then
  15.         warn("[RTS] License not active for group owner (Group ID: " .. placeOwnerID .. "). FlowMaster deleted.")
  16.     else
  17.         warn("[RTS] License not active for place owner (User ID: " .. placeOwnerID .. "). FlowMaster deleted.")
  18.     end
  19.     game.workspace["FlowMaster V1"]:Destroy()
  20. end
  21.  
  22.  
  23. local debug = false
  24.  
  25. game.ReplicatedStorage["RTS FlowMaster V1"].EstimatedTime.OnServerEvent:Connect(function(player, gate, esttime)
  26.     local Settings = require(game.Workspace["FlowMaster V1"].Configuration)
  27.  
  28.     -- Check if the player's rank is sufficient
  29.     if player:GetRankInGroup(Settings.ControllerConfig.GroupID) <= Settings.ControllerConfig.MinimumRank then
  30.         player.PlayerGui.FlowMaster.Configuration.GateNum:Destroy()
  31.         player.PlayerGui.FlowMaster.Configuration.Send:Destroy()
  32.         player.PlayerGui.FlowMaster.Configuration.TextBox:Destroy()
  33.         player.PlayerGui.FlowMaster.Configuration.LocalScript:Destroy()
  34.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = "[REQUEST INVALID] You cannot attempt to change gate status with under the required rank!"
  35.         wait(2)
  36.         player:Kick("[RTS FlowMaster] You have been kicked for attempting to change gate status when under the required rank! If you think this was a mistake, please contact support or check settings of the configuration.")
  37.         return
  38.     end
  39.  
  40.     -- Validate that the gate is a plain number
  41.     local isGateValid = tonumber(gate)
  42.     local isEstTimeValid = tonumber(esttime)
  43.  
  44.     if not isGateValid and not isEstTimeValid then
  45.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = "[INVALID REQUEST] Please enter a valid gate and estimated time number."
  46.         wait(2)
  47.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = ""
  48.         return -- Exit if both values are invalid
  49.     end
  50.  
  51.     if not isGateValid then
  52.         if debug then
  53.             warn("Invalid gate number (not a plain number):", gate)
  54.         end
  55.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = "[INVALID REQUEST] Please enter a valid number for the Gate."
  56.         wait(2)
  57.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = ""
  58.         return -- Exit if the gate is not a valid number
  59.     end
  60.  
  61.     if not isEstTimeValid then
  62.         if debug then
  63.             warn("Invalid estimated time number (not a plain number):", esttime)
  64.         end
  65.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = "[INVALID REQUEST] Please enter a valid number for the Estimated Time."
  66.         wait(2)
  67.         player.PlayerGui.FlowMaster.Configuration.Notice.Text = ""
  68.         return -- Exit if the estimated time is not a valid number
  69.     end
  70.  
  71.     local gateModelsFolder = game.Workspace["FlowMaster V1"]
  72.  
  73.     -- Debug print helper function
  74.     local function debugPrint(...)
  75.         if debug then
  76.             print(...)
  77.         end
  78.     end
  79.  
  80.     -- Debug warnings helper function
  81.     local function debugWarn(...)
  82.         if debug then
  83.             warn(...)
  84.         end
  85.     end
  86.  
  87.     debugPrint("Starting search for Gate:", gate)
  88.     debugPrint("Player:", player.Name, "Estimated Time:", esttime)
  89.  
  90.     -- Function to search models for Configuration script and validate GateNumber
  91.     local function searchAndCheckGateNumber(gate)
  92.         -- Ensure gateModelsFolder exists
  93.         if not gateModelsFolder then
  94.             debugWarn("Gate Models folder not found!")
  95.             return
  96.         end
  97.  
  98.         -- Loop through each model in the folder
  99.         for _, gateModel in pairs(gateModelsFolder:GetChildren()) do
  100.             if gateModel:IsA("Model") then
  101.                 debugPrint("Checking model:", gateModel.Name)
  102.  
  103.                 -- Check if the model has a Configuration ModuleScript
  104.                 local configModule = gateModel:FindFirstChild("Configuration")
  105.                 if configModule then
  106.                     if configModule:IsA("ModuleScript") then
  107.                         debugPrint("Found Configuration script in", gateModel.Name)
  108.  
  109.                         -- Require the Configuration ModuleScript to access its table values
  110.                         local success, config = pcall(function()
  111.                             return require(configModule)
  112.                         end)
  113.  
  114.                         if success then
  115.                             debugPrint("Successfully loaded configuration for", gateModel.Name)
  116.  
  117.                             -- Explicitly convert gate and GateConfig.GateNumber to numbers for comparison
  118.                             local gateNumberFromConfig = tonumber(config.GateConfig.GateNumber)
  119.                             local gateNumberToCheck = tonumber(gate)
  120.  
  121.                             -- Check if the GateNumber matches the provided number
  122.                             if gateNumberFromConfig and gateNumberToCheck and gateNumberFromConfig == gateNumberToCheck then
  123.                                 debugPrint("Gate number matched for model:", gateModel.Name)
  124.                                 local currentTime = os.date("%H:%M") -- Format: HH:MM
  125.                                
  126.                                 gateModel.StopandGo.Screen.SurfaceGui.Estimated.Text = esttime.." Minutes"
  127.                                 gateModel.StopandGo.Screen.SurfaceGui.Username.Text = "Set by " .. player.Name .. " at " .. currentTime
  128.                                 game.ReplicatedStorage["RTS FlowMaster V1"].GateUpdate:FireAllClients(config.GateConfig.GateName, esttime)
  129.                                
  130.                                 player.PlayerGui.FlowMaster.Configuration.Notice.Text = "[SUCCESS] You have successfully edited the targetted gate and it has been updated"
  131.                                 wait(2)
  132.                                 player.PlayerGui.FlowMaster.Configuration.Notice.Text = ""
  133.                                 -- Perform actions with the model (like opening doors)
  134.                             else
  135.                                 debugPrint("Gate number did not match. Expected:", gateNumberToCheck, "Found:", gateNumberFromConfig)
  136.                             end
  137.                         else
  138.                             debugWarn("Failed to load configuration for model:", gateModel.Name, "Error:", config)
  139.                         end
  140.                     else
  141.                         debugWarn("Configuration found but is not a ModuleScript in model:", gateModel.Name)
  142.                     end
  143.                 else
  144.                     debugWarn("No Configuration script found in model:", gateModel.Name)
  145.                 end
  146.             else
  147.                 debugWarn("Child is not a model:", gateModel:GetFullName())
  148.             end
  149.         end
  150.     end
  151.  
  152.     -- Execute search function with the provided gate number
  153.     searchAndCheckGateNumber(gate)
  154. end)
  155.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement