So I’ve recently stumbled across a lightweight admin system known as CMDR, and me and my Limited scripting knowledge has been trying to fix this for weeks,
So Starting off I have Ban Command and it uses return functions to work, so I’d like the code to remain relatively similar. It starts by formatting the time into a readable string for the ban message, which you can see via the Format and convertToHMS functions.
Then in a for loop it access’s a Database with the name being KGBan and the Scope being 5
It then creates a key (Player.UserId) and adds the necessary info inside it, Ban Start, Ban Duration, and the Ban Reason. It works perfectly so far, I’ve been banned for 1 minute ya da ya da, whatever
return function (_, players, length, reason, context)
local function Format(Int)
return string.format("%02i", Int)
end
local function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60
local Days = (Hours - Hours%60)/60
Hours = Hours - Days*60
return Format(Days)..":"..Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end
for _, player in pairs(players) do
local DDS = game:GetService("DataStoreService");
local Players = game:GetService("Players");
local BanStore = DDS:GetDataStore("KGBan", 5)
local function SetBan(Player, Reason, Duration)
local Success, Error = pcall(function()
BanStore:SetAsync((Player.UserId), {BanStart = os.time(), BanDuration = os.time() + (Duration * 60), BanReason = Reason});
end)
print(Duration)
Player:Kick("You have been banned for " ..convertToHMS(Duration).. " by an Admin for ".. Reason);
if not Success then
warn("Not successful.")
else
print(Duration)
end
end
local duration = length
local playerToBan = player
if playerToBan then
if duration then
if reason then
SetBan(playerToBan, reason, duration);
print("Player has been kicked!");
end
end
end
return ("Banned %d players."):format(#players)
end
The problem comes as I have another script which should ban players on join. This is for if they still have an outstanding ban time, however when formatting the “Timer” it shows a number which is 10x that of the ban I gave my self.
Here is the block of code I have for it
game.Players.PlayerAdded:Connect(function(Player)
print("Playerjoined")
local DDS = game:GetService("DataStoreService");
local BanStore = DDS:GetDataStore("KGBan", 5)
local Success, Result = pcall(function()
return BanStore:GetAsync(Player.UserId)
end)
local function Format(Int)
return string.format("%02i", Int)
end
local function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60
local Days = (Hours - Hours%60)/60
Hours = Hours - Days*60
return Format(Days)..":"..Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end
if Success and Result then --see if datastore request was successful
if (Result.BanDuration - os.time()) > 0 then --check if any data for the player was found
print(Result.BanDuration)
Player:Kick("You have been banned for " ..convertToHMS(Result.BanDuration).. " by an Admin for ".. Result.BanReason);
end
end
end)
So I guess what I’m asking is where might it be failing and how could I potentially fix this in the future. Any help would be appreciated.