How to ban a player for a selected amount of time?

I know how to store the data that he should be banned but I don’t know how to ban him temporarily,
I know that you have to use os.time but I dont understand the math that I have to do to either let him stay or kick him. Like what do I store as the “BanLength” and how to I subtract the right amount of time
and how to I format it so it says “You have been banned for 1 day, 1 hour, 1 minute” when he gets kicked with :Kick(), please help me.

No matter how many times I read about os.time on the developer forum I wont understand it.

Simplified bc I’m terrible at writing.

  1. I will use a function to ban the player with 2 parameters ban(day, hour) so
    I need to convert those parameters into a format(pretty sure at least)
  2. What time do I store when I kick the player.
  3. How do I format the time to days, hours.
  4. What math do I do when the banned player joins and format the new time to tell
    him how much he has left.
2 Likes

local oneday = 86400 – seconds

local oneminute = 60 – seconds

local onehour = 3600 – seconds

local chosen = nil

Also if you want to ban them for multiple days or seconds, just do this

onehour = onehour * 2 – this would equal two hours.

oneday = oneday * 2 – this would equal two days

oneminute = oneminute * 2 – this would equal two minutes

local BanTime = 60
BanTime = BanTime * chosen

local StartBanTime = os.time() – The Current Time

local EndTime = BanTime + StartBanTime – Caculates the amount of time for that ban.

Bans:SetAsync(player,{StartBanTime,BanTime,msg,EndTime})

If you have any remote events, just use the chosen to pick the minute/hour or ban if it’s a GUI.

4 Likes

Also to get an actual date os.date could be useful for that

1 Like

Thank you so much, ill try figuring out the other part for myself using os.date like @michialok said.