Auto unsuspend player in 100 days

Hi, I’m using DataStore in my game to suspend someone if he’s cheated:

local DataStore = game:GetService("DataStoreService"):GetDataStore(Player.UserId.."Data")
local Data = DataStore:GetAsync("Suspended")

But how can I make it to automatically unsuspend the player if player was suspended for 100 days? (I don’t know how to use os.time() in scripting). Please, help me!


os.time() returns the time in seconds since the start of the year.
If you save os.time(), when the player joins, you can subtract it from the current os.time() - and if the result is greater than the number of seconds 100 days would take, don’t kick them. Otherwise, kick them.

by the way, also use a pcall() with GetAsync().

local timeGap = os.time() - Data
if timeGap > The_100_days_in_seconds_here then
    --player doesn't get kicked

Thank you, but I don’t know how can I use it, and what Data on the first line should to be.

1 Like

The “Suspended” in my script when :GetAsync can be only setted to true or false value, so I don’t know how can I use it in your script.

You need to save an array to the store, then.

When saving:

local saveData = {
    ["Banned"] = true,
    ["SuspensionTime"] = os.time()
--Do not save this data when a player leaves.
--It would mess it up if it saved every time a banned player joined and got kicked.
local success, result = pcall(function()
    DataStore:SetAsync(key, saveData)
if not success then

Then, on loading:


local timeSeconds = 8640000

local data
local success, result = pcall(function()
    data = DataStore:GetAsync(key)
if success and data then
    if os.time() - data.SuspensionTime <= timeSeconds then
        player:Kick("You are still banned.")
1 Like

He doesn’t need an Array.

having a value is already not false, therefore, setting the value of “Banned” as the time they were banned (or even better, the time when the Ban will be done) already counts as “true”.

just check make the “is banned check” a " tonumber( value )~=nil " and you’re good.

Is banned? value is a number.
isn’t banned? value is nil.

no booleans needed, information can be stored there.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.