-
What do you want to achieve?
I want to ban the player for a selected amount of time. -
What is the issue?
Everytime I join after I got banned the time doubles. -
What solutions have you tried so far?
I looked around on the DevForum.
BanScript
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("SimpliCmdBans4")
local SS = game:GetService("ServerStorage")
local module = {
Ban = function(plr, reason, banLengthM, banLengthH, banLengthD)
local Id = plr.UserId
local banData = {
banned = false,
startTime = 0,
endTime = 0,
reason = ""
}
banData.banned = true
banData.startTime = os.time()
banData.endTime = banData.startTime + (banLengthM * 60 + banLengthH * 3600 + banLengthD * 86400)
banData.reason = reason
DS:SetAsync(Id, banData)
plr:Kick("Banned".."\n"..reason.."\n".."Time left: "..tostring(banData.endTime - os.time()).." seconds.")
end,
UnBan = function(plr)
local Id = plr.UserId
local banData = {
banned = false,
startTime = 0,
endTime = 0,
reason = ""
}
DS:SetAsync(Id, banData)
end,
}
return module
Check ban script
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetDataStore("SimpliCmdBans4")
local SS = game:GetService("ServerStorage")
local cmds = require(script.Parent.Commands)
local module = {
turnToTime = function(timeNumber)
local minutes = timeNumber / 60
local hours = minutes / 60
local days = hours / 24
return minutes, hours, days
end,
CheckBan = function(plr)
local Id = plr.UserId
local banData
local success, warnd = pcall(function()
banData = DS:GetAsync(Id)
end)
if success then
if banData.banned then
if banData.endTime - banData.startTime <= 0 then
cmds.UnBan(plr)
print("Player unbanned")
return
end
local minutes = (banData.endTime - banData.startTime) / 60
local hours = minutes / 60
local days = hours / 24
if minutes < 0 then minutes = 0 end
if hours < 0 then hours = 0 end
if days < 0 then days = 0 end
cmds.Ban(plr, banData.reason, minutes, hours, days)
end
end
end,
}
return module
(The “CheckBan” function gets called when a player joins the game)