RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Make an advanced automatic train system."
-- server script -- Get the required services local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Set up the variables local TrainStations = ReplicatedStorage.TrainStations local TrainRoutes = ReplicatedStorage.TrainRoutes -- Set up the functions local function getTrainRoute(TrainRoute) local TrainRouteTable = {} for _, TrainStation in pairs(TrainRoute:GetChildren()) do table.insert(TrainRouteTable, TrainStation.Value) end return TrainRouteTable end local function getTrainStation(TrainStation) local TrainStationTable = {} for _, TrainRoute in pairs(TrainStation:GetChildren()) do table.insert(TrainStationTable, TrainRoute.Value) end return TrainStationTable end local function getTrainRouteFromStation(TrainStationName) local TrainStation = TrainStations[TrainStationName] if TrainStation then local TrainStationTable = getTrainStation(TrainStation) local TrainRouteTable = {} for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) table.insert(TrainRouteTable, RouteTable) end return TrainRouteTable end end -- Set up the events Players.PlayerAdded:Connect(function(Player) Player.CharacterAdded:Connect(function(Character) Character.Humanoid.Died:Connect(function() local TrainStationName = Character.HumanoidRootPart.Position local TrainRouteTable = getTrainRouteFromStation(TrainStationName) if TrainRouteTable then for _, TrainRoute in pairs(TrainRouteTable) do for _, TrainStationName in pairs(TrainRoute) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainRoutes[TrainRouteName] local RouteTable = getTrainRoute(TrainRoute) for _, TrainStationName in pairs(RouteTable) do local TrainStation = TrainStations[TrainStationName] local TrainStationTable = getTrainStation(TrainStation) for _, TrainRouteName in pairs(TrainStationTable) do local TrainRoute = TrainR