Hello,
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")
else
print("player is banned")
end
end
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.