Attempt to index nil with number

I keep getting “attempt to index nil with number” on the following code.
I have tried to figure out the issue myself but I haven’t found the problem.
Here is the code:

local datastoreservice = game:GetService("DataStoreService")
local bandata = datastoreservice:GetDataStore("Bans")

local data = bandata:GetAsync(Players[player].UserId)
			if data[1] == Players[player].UserId then -- the error line I get for attempt to index nil with number
				if os.time() >= data[2] then -- when the player is still banned
					print("player is not banned")
				elseif data[2] == "." then -- when the player has been unbanned the data[2] is set to "." instead of removing the player from datastore
					print("player is not banned")
					print("player is banned")

I think players[player] is nil if player isn’t a variable

1 Like

The “player” is a textbox

CheckBan.OnServerEvent:Connect(function(myplayerhere, player)

The data might be nil print the data and put an if statement

1 Like

Yep it is. Do you know how to fix it?

You need to check how your saving your data since its nil it means nothing is being saved. If you need further help show the part of the code that saves the data.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.