Table from ModuleScript returning nil

Hello Dear DevForum community, I have lately encountered this very strange bug.
My ModuleScript doesn’t return the table but nil, I have seen many posts about this already but I cant
fix it.

My Goal is it to get the CHASSIS table and then inside of it the maxturnangle, the problem is it returns nil, even tho if I try to get any other table it works except for the CHASSIS.

local Cars = {
	["Hyundai i20"] = {
		NAME = "Hyundai i20",
		ID = 1,
		ENGINE = {
			displacement = "1.2",
			stroke_length = "0.0756",
			fuel_type = "Gasoline 95",
			cylinders = 4,
			maximum_rpm = 8000
		},
		TRANSMISSION = {
			Transmissiontype = "Manual",
			gearRatios = {
				["Reverse"] = -3,
				["Neutral"] = 0,
				["Gear1"] = 3,
				["Gear2"] = 2,
				["Gear3"] = 1.5,
				["Gear4"] = 1.25,
				["Gear5"] = 1
			}
		},
		CHASSIS = {
			MaxTurnAngle = 45
		},
		
	}
}

return Cars

And initially I got this bug when doing it in a localscript (the modulescript is accessable for the localscript so that isnt the problem), and then I just tested it out in the console and it just doesnt work.

print(require(ModuleScriptLocation["Hyundai i20 info"])["Hyundai i20"].CHASSIS)

All the other values work but the Chassis doesnt, I really appreciate help, thanks!
EDIT: I have also noticed when printing the entire table, CHASSIS isnt the only one that doesnt get printed, for example cylinders and maximum_rpm also get excluded and they are all int values so could that have to do something with the problem?

1 Like

i was unable to replicate this issue, heres my code:

local module = require(game:GetService('ReplicatedStorage'):WaitForChild('ModuleScript'))

print(module["Hyundai i20"].CHASSIS)

image

2 Likes

I thought if it could be a studio bug? Because I really dont see any problem with the code and you tested it out and doesnt seem to be a problem…

1 Like

I see the issue, you’re forgot to add a right parenthesis after ModuleScriptLocation. You’re trying to access the table BEFORE you required the module script so Roblox thinks that “Hyundai i20 info” is a child of the module script.

You need to do this instead:

print(require(ModuleScriptLocation)[“Hyundai i20 info”][“Hyundai i20”].CHASSIS)
1 Like

In their code they assigned the required module script to a variable and then they were able to access the table.

In your code you attempted to require “Hyundai i20 info” because you tried to access the contents of the table before you required the module itself if that makes sense

Your code:

print(require(ModuleScriptLocation[“Hyundai i20 info”])[“Hyundai i20”].CHASSIS)

What it should be:

print(require(ModuleScriptLocation ) [“Hyundai i20 info”][“Hyundai i20”].CHASSIS)

Notice in your code that you’re trying to require the “Hyundai i20 info” table which is NOT a module script so it returns nil (also because the script doesn’t really know it exists because it gets RETURNED AFTER you require the module script)

1 Like

Yeah that makes sense thanks I cant test it out but im sure that is the solution.

2 Likes