My time ban is working in terms of setting and checking but automatically sets it as false ('Un Ban Time')
Here is the Code:
local DataStoreService = game:GetService("DataStoreService")
local TempBanStore = DataStoreService:GetDataStore("TempBanStore")
local Times = {
OneDayBan = 86400, -- One day ban in seconds
ThreeDayBan = 259200, -- Three day ban in seconds
FiveDayBan = 432000, -- Five day ban in seconds
}
game.Players.PlayerAdded:Connect(function(Player)
local Success, Result = pcall(function()
return TempBanStore:GetAsync(Player.UserId,"TempBan")
end)
if Success then
if Result then
if Result.BanStartTime + Result.BanTime < os.time() then
Player:Kick("You are temp-banned")
print('Still Banned')
else
print('unban')
end
end
end
end)
function banTimeSet(banTime)
if banTime == 'one_day' then
return Times.OneDayBan
elseif banTime == 'three_days' then
return Times.ThreeDayBan
elseif banTime == 'five_days' then
return Times.FiveDayBan
elseif banTime == '' or banTime == nil then
return print('none')
end
end
game.Players.PlayerAdded:Connect(function(plr)
if plr.Name == 'CRAZYQUACKY84' then
plr.Chatted:Connect(function(cmd)
local args = cmd:split(' ')
if args[1] == ':ban' then
local plrToBan = game.Players:FindFirstChild(args[2])
banTimeSet(args[3])
if plrToBan then
TempBanStore:SetAsync(plrToBan.UserId, {BanStartTime = os.time(), BanTime = banTimeSet(args[3])})
plrToBan:Kick('You have been banned for 3 days')
end
end
end)
end
end)
Likewise, everything works with no error, it even prints the time set, ban Time but the if condition may be false? idk. :P

1 comment
Looking through this rn, I know this isn't about why it isn't working, but you shouldn't use a Username for telling the server who is an Admin and who is not. If you change your username it might not work. I would recommend using UserIds instead. Ex: plr.UserId == 99404087