-
What do you want to achieve? I want to save an array to my datastore so that I can ban people from my game. Right now I am having a bug where when nobody is banned, I try to save an array to the datastore it throws an error
-
What is the issue? For some reason saving an array to my datastore does not work. It says that I am trying to call a nil value
-
What solutions have you tried so far? I have searched throughout Google and the Devforums and have followed the developer article
Here are the developer console errors
Here is some of my code (This Code is Run Every Time someone Joins the game)
local DataStoreService = game:GetService("DataStoreService")
local RunService = game:GetService("RunService")
if not RunService:IsStudio() then
print("BannedStore Created")
local BannedStore = DataStoreService:GetDataStore("PlayersBanned")
end
---- \/ Code That Runs When Player Joins \/ ----
local repeatTimes = 0
print("About to Run")
if not RunService:IsStudio() then
local BansList
repeat wait(.1)
repeatTimes += 1
local success, err = pcall(function() -- Checks Banned Datastore
BansList = Banned:GetAsync("Bans")
end)
if not BansList then
print(Banned)
repeat wait(.1) -- Gets Stuck in This Loop
print("Relooping")
local success1, err1 = pcall(function()
Banned:SetAsync("Bans", {2646833 --[[UserID's Here]]}) -- Error is here
end)
if success1 then
print("Success!")
else
print(err1)
end
until success1
print(BansList)
end
if success then
if table.find(BansList, UserID) then
player:Kick("You have been banned from this game! If this is a mistake please contact the game creator.")
end
end
until success or repeatTimes >= 10
if repeatTimes >= 10 then player:Kick("Gameknight Commands- Error Code: 100, Please Rejoin!") warn(tostring(player).."'s Datastore Failed!") end
end
NOTE: I am running this code NOT on studio.
(Its probably something easy that I’m overlooking, thank you for helping In advance)