So I am making a ban system and want to save the player's ban data every time they leave and retrieve their ban data when they join and to test it i want to print the player's ban data , when me the script tries to print it it errors and says "Table expected, got Instance. I don't know why it says this because the ban data is a table, not an instance. Here is the script:
local DSS =game:GetService("DataStoreService")
local data= DSS:GetDataStore("BanData")
local banbegantime
local pbantime
local banreason = ""
game.ReplicatedStorage.OnBan.OnServerEvent:Connect(function(p,target,bantime,reason)
target.IsBanned.Value = true
target:Kick("You have been banned:".. reason)
pbantime = bantime
local bannedplr = game.Players:FindFirstChild(target)
local startbantime = os.time()
banbegantime = os.time()
if bannedplr then
bannedplr.IsBanned.Value = true
bannedplr:Kick(reason)
end
banreason =reason
end)
game.Players.PlayerAdded:Connect(function(plr)
local times ={
Minute = 60,
Hour =3600,
Day = 86400,
Month = 2592000,
Year = 31104000
}
local userId = "Player_".. plr.UserId
wait(3)
data:GetAsync(userId)
for i,v in pairs(data) do
print(v)
end
local banstarted = data[2]
local bantime = data[3]
local Playerbanreason = data[4]
local timeleft
if plr.IsBanned.Value == true then
plr:Kick(Playerbanreason)
else
if bantime/times.Year >0 then
timeleft = bantime/times.Year.. "Years"
end
if bantime/times.Month >0 then
if bantime/ times.Month >1 then
timeleft = timeleft.. bantime/times.Month.. "Months"
else
timeleft = timeleft.. bantime/times.Month.. "Month"
end
end
if bantime/times.Day >0 then
if bantime/ times.Day >1 then
timeleft = timeleft.. bantime/times.Day.. "Days"
else
timeleft = timeleft.. bantime/times.Day.. "Day"
end
end
if bantime/times.Hour >0 then
if bantime/ times.Hour >1 then
timeleft = timeleft.. bantime/times.Hour.. "Hours"
else
timeleft = timeleft.. bantime/times.Hour.. "Hour"
end
end
if bantime/times.Minute >0 then
if bantime/ times.Minute >1 then
timeleft = timeleft.. bantime/times.Month.. "Minutes"
else
timeleft = timeleft.. bantime/times.Month.. "Minute"
end
end
local reasonforban = Playerbanreason.. "\n Your ban will be lifted in: \n".. timeleft
plr:Kick(reasonforban)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local userId = "Player_".. plr.UserId
local bandata= {}
table.insert(bandata,1,plr.IsBanned.Value)
table.insert(bandata,2,banbegantime)
table.insert(bandata,3,pbantime)
table.insert(bandata,4,banreason)
local succes,err = pcall(function()
data:SetAsync(userId,bandata)
end)
print("Saving data...")
if not succes then
warn("Could not save ban data")
end
end)
Could someone please tell me what I'm doing wrong?

3 comments
You need to assign variable to the loaded data at (36) data:GetAsync(userId) because on line 38 you are then looping through DSS:GetDataStore("BanData") which is a DataStore, Instance. Also FindFirstChild() takes string as first argument, on line 13 you are passing Player, it also makes no sense as the variable already refers to the gamer.
Would I do that like this: isbanned.Value = data:GetAsync(userId[1])?
Nevermind. Thanks a lot though!