The error is: attempt to index with a nil number (line 12)
Code:
local bans = game:GetService("DataStoreService"):GetDataStore("TempZens21e45")
game.Players.PlayerAdded:Connect(function(player)
local banData
local good, bad = pcall(function()
banData = bans:GetAsync("plrs_"..tostring(player.UserId))
end)
if bad then
warn("Error getting datastore: "..bad)
end
if banData ~= {} then
local prevtime = banData[1]
local reason = banData[2]
local banlength = banData[3]
if os.time() < (prevtime+banlength) then
local timeleft = (prevtime+banlength)-os.time()
local hours = math.floor(timeleft/3600)
local hs = timeleft % 3600
local days = math.floor(timeleft/86400)
local mins = math.floor(hs/60)
local secsleft = hs%60
player:Kick(reason.. "\nYou will be unbanned in: "..days.." days, "..hours.." hours, "..mins.." minutes and "..math.floor(secsleft).. " seconds.")
else
local g,b = pcall(function()
bans:SetAsync("plrs_"..tostring(player.UserId),{})
end)
if g then
print("player waited their time and got unbanned succesfully.")
else
warn("error setting datastore: ".. b)
bans:SetAsync("plrs_"..tostring(player.UserId),{})
end
end
end
end)
function BanPlayer(userid,timeinseconds,reason)
if game.Players:GetPlayerByUserId(userid) then
local timeleft = timeinseconds
local hours = math.floor(timeleft/3600)
local hs = timeleft % 3600
local days = math.floor(timeleft/86400)
local mins = math.floor(hs/60)
local secsleft = hs%60
game.Players:GetPlayerByUserId(userid):Kick(reason.. "\nYou will be unbanned in: "..days.." days, "..hours.." hours, "..mins.." minutes and "..math.floor(secsleft).. " seconds.")
local g,b = pcall(function()
bans:SetAsync("plrs_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plrs_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
else
local g,b = pcall(function()
bans:SetAsync("plrs_"..tostring(userid),{os.time(),reason,timeinseconds})
end)
if g then
print("succesfully banned player.")
else
warn("error setting ban datastore: "..b)
bans:SetAsync("plrs_"..tostring(userid),{os.time(),reason,timeinseconds}) -- attempt agian.
end
end
end
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if string.lower(msg) == "clown" then
BanPlayer(plr.UserId,200000,"your the clown")
end
end)
end)