Hello, I am currently developing a system for a Bus Shift style game and I am stumbling across an issue with a script involving table indexing (in this case getting values from it).
In short, this system keeps “Chapas” (“Chapas” are basically groups of Timetables for a driver/bus during the shift) and distributes them to buses from an UI which is controlled by an “operator”. The bus then receives the “Chapa” and from there it starts it’s journey when the driver configures the proper destination.
The way it handles Timetables is through “UniqueIDs”, that are registered as the Order in the Timetable Array (Stored in another script)
The part of the system where I’m having the issue is where it changes to the next Timetable inside the “Chapa”. When it changes to the next Timetable it will wait for the driver to set the next destination that corresponds to the destination in the next Timetable. This is where I get my error!
This is where it changes to the next Timetable, as you can see there is a protected function that exists in case there are no more Timetables left:
nextEvent.Event:Connect(function()
local Timetable = {}
Timetable = workspace.Timetables.GetTimetableSERVER:Invoke()
Timetable[script.Parent.Parent.TimetableUniqueID.Value][4] = false
workspace.Timetables.WriteToTimetable:Fire(Timetable)
table.remove(TimetableList, 1)
task.wait(1)
print(TimetableList[1].." - "..TimetableList[2].." ROUTE NUMBER: "..script.Parent.Parent.RouteNumber.Value)
if real then
print("Success")
else
warn("FINISH CHAPA "..errorMsg)
script.Parent.Parent.TimetableUniqueID.Value = 0
local Database = Chapas.GetChapaDataSERVER:Invoke(script.Parent.Parent.Line.Value)
Database[script.Parent.Parent.ChapaNumber.Value][1] = false
Database[script.Parent.Parent.ChapaNumber.Value][2] = 0
Chapas.WriteDataSERVER:Fire(script.Parent.Parent.Line.Value, Database)
script.Parent.Parent.isInRoute.Value = false
end
end)
Here is the protected function along with the variables (ABOVE the section showed before, all inside the same script) (please ignore the silly names ) :
local TimetableList = {}
local nextEvent = script.Parent.Parent.NextTimetable
local Chapas = workspace.ChapaDatabase
local real, errorMsg = pcall(function()
local Timetable = {}
Timetable = workspace.Timetables.GetTimetableSERVER:Invoke()
print(TimetableList)
repeat
print("Waiting...")
--print(Timetable[TimetableList[1]][1])
print(TimetableList[1])
task.wait(1)
until script.Parent.Parent.RouteNumber.Value == Timetable[TimetableList[1]][1]
if script.Parent.Parent.isInRoute == true then
script.Parent.Parent.TimetableUniqueID.Value = TimetableList[1]
Timetable[script.Parent.Parent.TimetableUniqueID.Value][4] = true
workspace.Timetables.WriteToTimetable:Fire(Timetable)
end
end)
The area that gives out the error is in the “until”. It returns this error:
The area that is giving out the error basically compares the first value of a Timetable inside an array that is returned when Invoking the Script that stores them. Because other elements of my system do the same thing, I know for sure it correctly gets the Timetable.
For reference, this is an example of an array element for each Timetable:
{"R00701", 7, 2, false, 0, 0, {"00:00" , nil, nil, nil, nil, nil, nil, nil, nil, nil}},
The issue is that while there are Timetables still existing, it gives out an error so it thinks there are no more Timetables left In this case you can see that “Timetable List” had 3 values and then one of them got removed (those values were manually added in the system for testing reasons). So the issue of the Array being empty is out the table. Then I checked if the Value was “nil”, which, from the picture, it’s not.
After trying many different fixes I am still facing this problem. I hope I gave all the necessary info. If there is anything I can provide more about the issue feel free to ask! Thanks a lot in Advance!