I need help making a timetable system. The trains will spawn according to the timetables.
I tried making a script, but failed.
I tried looking on the DevForum, YT, and documentation, nothing
Any help is appreciated. Thanks!
I need help making a timetable system. The trains will spawn according to the timetables.
I tried making a script, but failed.
I tried looking on the DevForum, YT, and documentation, nothing
Any help is appreciated. Thanks!
A timetable is a very vague description of what you’re trying to achieve, so if you could provide more detail, I’d be glad to help!
If I had to guess, I’d assuming you want to make a time system and with that time system, make trains spawn at certain times?
Yes, that’s what i’m trying to achieve
Okay, well I’m not sure if you know how to make classes via ‘SetMetaTable’, so I’ll explain the concept and you can modify it as you’d like.
local trainTime = 0
local maxTime = 300
while true do
task.wait(1)
if trainTime == maxTime then
trainTime = 0
continue
end
trainTime += 1 -- Adds 1 to the existing value of trainTime
end
(You can wrap this in a coroutine if you need to have more things inside of this script)
So this basically loops through the max amount of time infinitely, and that only. You can add a ‘BindableEvent’ or ‘BindableFunction’ to this loop to update other scripts about the time within the loop.
This script is to be standalone and to be your ‘TimeSystem’. You use the BindableEvents or BindableFunction to communicate between scripts, so you can modulate your code.
(Modulating your code is EXTREMELY important for organization and as your game gets bigger, imo)
I hope that helps and if you need clarification on something, let me know.
Well making an actual train on a timetable is very simple from a code point of view, what you might find difficult on the contrary is making it look professional.
If I were to personally try and achieve this then I would frankly use a time stamp system based on tick(), with different trains running a specific cycle (you can then convert tick() to a time date system) on repeat. This is very similar to how real trains run in real life.
You should then treat the organisation of a train as very independent, you should have:
In general this whole thing is just one big continuance of data. The main script should simply record if a track is free or not, and then based on what lines are free assign a train towards it.
Whilst making this is quite easy, the main difficulty you will probably find is making it look neat to begin with.
A more complex system might adopt a globalised all server timetable, these can either use an API or have a server which runs as the primary system.
You do have one advantage though:
Trains will never enter the same line of track as another train, so you are more then welcome to add wait times between trains with no issue! Based on tick() alone you can even estimate how long until the train arrives!
I managed to make a quick UTC time system. My game uses UTC time to run the trains.
My idea is to somehow make it spawn when the clock strikes a certain time e.g 13:39, 13:44, 13:49, however i have not come up with anything that works yet.
The automation is already done.
And I attempted doing this using tables, however it didn’t work
If you set up a single time code for a time you are already aware of, you can use this time code to manipulate your times accordingly.
If you want very specific times, I would honestly use a combination of modulo / base division (to work out the current day) and then increment based on these values a certain amount (based on seconds in the day in unix time).
Equally, using regex can also tell you the current time by converting the time away. Honestly I wouldn’t worry about time specific trains however, they tend to be a lot more unenjoyable in Roblox - most people just want to catch a train when they can.