I’m attempting to make a time ban that uses DataStores and os.time(). I originally found this code from another post, so I decided to test it out and expand with it. However, I came across this error when I tried testing it out for myself.
I came across an error that stated: Argument 1 missing or nil
this leads to line 15, which is TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.OneDayBan})
Code:
local DataStoreService = game:GetService("DataStoreService")
local TempBanStore = DataStoreService:GetDataStore("TempBanStore",1)
local Times = {
OneDayBan = 86400, -- One day ban in seconds
ThreeDayBan = 259200, -- Three day ban in seconds
FiveDayBan = 432000, -- Five day ban in seconds
PermBan = 1,870,329,440 -- Perm ban in seconds (date is set to 2050)
}
game.ReplicatedStorage.RequestBan.OnServerEvent:Connect(function(Administrator, Player, Reason, BanTime)
if Administrator:GetRankInGroup(2995276) >= 19 then -- Checks if the player is over the rank "Developer"
if BanTime == "OneDay" then
TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.OneDayBan})
end
elseif BanTime == "ThreeDay" then
if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
local NewPlayer = game.Players:GetPlayerByUserId(Player.Name)
TempBanStore:SetAsync(tonumber(Player.UserId), {BanStartTime = os.time(), BanTime = Times.ThreeDayBan})
end
elseif BanTime == "FiveDay" then
if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
TempBanStore:SetAsync(tostring(Player.UserId), {BanStartTime = os.time(), BanTime = Times.FiveDayBan})
end
elseif BanTime == "PERM" then
if Player:GetRankInGroup(2995276) < 19 then -- Checks if the player is under the rank "Developer"
TempBanStore:SetAsync(tostring(Player.UserId), {BanStartTime = os.time(), BanTime = Times.PermBan})
end
else
Administrator:Kick("\nDon't exploit!\n") -- Kicks the player if they don't have the required group rank
end
end)
game.Players.PlayerAdded:Connect(function(Player)
local Success, Result = pcall(function()
return TempBanStore:GetAsync(tostring(Player.UserId),"TempBan")
end)
if Success then
if Result then
if Result.BanStartTime + Result.BanTime > os.time() then
-- No ban set for this user
else
Player:Kick("You are temp-banned")
end
end
end
end)