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!

4 Likes

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
end
2 Likes

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:

--example
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)
end)
if not success then
    warn(result)
end

Then, on loading:

--example

local timeSeconds = 8640000

local data
local success, result = pcall(function()
    data = DataStore:GetAsync(key)
end)
if success and data then
    if os.time() - data.SuspensionTime <= timeSeconds then
        player:Kick("You are still banned.")
    end
end
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.