I have been stuck on how to make this work for months now (mostly because I haven't been using Roblox Studio for a while. I don't know if I'm doing something wrong in terms of getting the datastore. I attempt to GetAsync inside a pcall, but every time I do so it always returns nil. Is there some way to stop this?
The error being thrown:
15:51:40.445 Workspace.BlacklistHandler:115: attempt to index nil with 'BanTime' - Server - BlacklistHandler:115
local bantable=nil
local success, err = pcall(function()
bantable=PlayerStats:GetAsync(player.Name.." BanStats")
end)
if success and bantable ~= nil then
BanTime.Value = bantable.BanTime
BanReason.Value = bantable.BanReason
BanSender.Value = bantable.BanSender
else
BanTime.Value = 0
BanReason.Value = nil
BanSender.Value = nil
end
wait(1)
if success then
if os.difftime(os.time(),bantable.BanTime)<bantable.BanTime then -- and player.UserId~=29320767
if bantable.BanTime==math.huge then
player:Kick("You're permabanned! Reason:"..bantable.BanReason)
elseif os.difftime(os.time(),bantable.BanTime)>86400*7 then
player:Kick("You're still banned for ".. math.ceil(((os.difftime(os.time(),bantable.BanTime))/86400*7)).." weeks(s). Reason:"..bantable.BanReason)
elseif os.difftime(os.time(),bantable.BanTime)>86400 then
player:Kick("You're still banned for ".. math.ceil(((os.difftime(os.time(),bantable.BanTime))/86400)).." days(s). Reason:"..bantable.BanReason)
elseif os.difftime(os.time(),bantable.BanTime)>3600 then
player:Kick("You're still banned for ".. math.ceil(((os.difftime(os.time(),bantable.BanTime))/3600)).." hour(s). Reason:"..bantable.BanReason)
elseif os.difftime(os.time(),bantable.BanTime)>60 then
player:Kick("You're still banned for ".. math.ceil(((os.difftime(os.time(),bantable.BanTime))/60)).." minutes(s). Reason:"..bantable.BanReason)
end
end
else
error(err)
end

2 comments
You're wasting the function do this instead "return PlayerStats:GetAsync(player.Name.." BanStats")" : line 3
You should store your data store keys as their UserIds instead because if a player changed their name they would be unbanned