Code:
local DataStoreService = game:GetService("DataStoreService")
local LastLone = DataStoreService:GetDataStore("PlayerLastOnline")
local Min_Seconds = 120
local function Record_Time(Player)
local success, errorMessage = pcall(function()
LastLone:SetAsync(Player.UserId, os.time())
end)
if not success then
print(errorMessage)
end
end
local function CheckIfAllowed(Player)
local success, ErrorMessage = pcall(function()
local last_recorded_time = LastLone:GetAsync(Player.UserId)
local Time_Needed = last_recorded_time + Min_Seconds
if Time_Needed <= os.time() then
print("Played is allowed in!")
Record_Time(Player)
else
local Time_Needed = last_recorded_time + Min_Seconds
local Time_Predicted = Time_Needed - os.time()
Player:kick("Your currently on application cooldown, please rejoin in: " ..math.floor(Time_Predicted/60+0.5).. " minutes.")
end
end)
end
game.Players.PlayerAdded:Connect(function(Player)
if LastLone:GetAsync(Player.UserId) == nil then
Record_Time(Player)
else
CheckIfAllowed(Player)
end
end)