Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

"Attempt to index nil with number?"

Hey all! After a (long) hiatus from scripting, I'm back! This time working on another weather-related project, completely separate from the last one. I'm running some tests, and I came across this error: "attempt to index nil with number." I'm making a system which retrieves data from a module script in ReplicatedStorage, then pastes it onto a UI.

LocalScript:

local rs = game:GetService("ReplicatedStorage")
local weatherData = require(rs:WaitForChild("WeatherData"))

local bar = script.Parent
local radar = bar.Radar
local gameSettings = bar.Settings
local gameTime = bar.Time
local windspeed = bar.Windspeed
local rainlevel = bar.RainLevel
local category = bar.Category

function update()
	local data = weatherData:GetInfo()
	
	gameTime.Text = data[1]		--Pretty much this whole part errors
	windspeed.Text = data[2].." MPH"
	rainlevel.Text = data[3].." Rain"
	category.Text = "CAT "..data[4]
end

update()

ModuleScript:

local lighting = game:GetService("Lighting")
local module = {}

module.gameTime = lighting.TimeOfDay
module.windspeed = 0
module.rainlevel = "None"
module.category = 0

function module:GetInfo()
	local data = {module.gameTime, module.windspeed, module.rainlevel, module.category}
end

return module

Plz help!

1 answer

✓ Accepted answer

module:GetInfo() doesn't return anything.

Also, for future reference, the error means that you tried to index (i.e. use [ and ] to access an item) nil (i.e. data) with a number 1.

1 comment

0

omg lol im so dumb. As I said, I did take a long time away from scripting tho XD

This discussion is preserved as it was. New answers, comments, and votes are closed.