How to make a script know how long days, hours and minutes are?

Hi, I am trying to make a ban-panel where the kick function already works. But I don’t know how I can make the script know how long days, hours and minutes are. Do I need to make a data store or something diffrent? I really need help at making this. Here’s the script:

local Admins = {
	0,
	0,
	0,  -- these are the admins

}

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")


local KickEvent = ReplicatedStorage:WaitForChild("Kick")

local CheckIfAdmin = ReplicatedStorage:WaitForChild("CheckPlayer")
local shutdown = ReplicatedStorage:WaitForChild("Shutdown")
local KickAllPlayers = ReplicatedStorage:WaitForChild("KickAllPlayers")

local BanEvent = ReplicatedStorage:WaitForChild("Ban")
local manualBan = {}

local DateStoreService = game:GetService("DataStoreService")
local banDataStore = DateStoreService:GetDataStore("banDataStore")

BanEvent.OnServerEvent:Connect(function(player, PlayerName, Reason, days, hours, minutes)

-- I really dont know how I can make the script know how long days, hours and minutes are.

	if table.find(Admins, player.UserId) then
		local playerFound = Players:FindFirstChild(PlayerName)
		
		local playerUserId = player.UserId
		
		local banned
		local succes, errormessage = pcall(function()
			banned = banDataStore:GetAsync(playerUserId)
end)
		if playerFound then
			if playerFound.Name == "PVP_Player2373902" or playerFound.Name == "Tastysam_lol" then
				warn("Unable to ban Player!")
				return
			else	
				playerFound:Kick(Reason)
				task.wait(3)
				if game.Players:FindFirstChild(PlayerName) == true then
					warn("Error while kicking player!")
					return
				end
			end

		end
	else
		player:Kick("PUT YOUR HAND AWAY FROM MY ADMIN-PANEL") -- this happens if a non-admin is using the kick/ban-panel
	end
end)

game.Players.PlayerAdded:Connect(function(player) -- this is supposed to kick a player who is banned.

	local playerUserId = player.UserId

	if manualBan[playerUserId] then
		player:Kick("You are still banned because of:... Bantime left: ...d ...h ...s")
	end

	local banned
	local succes, errormessage = pcall(function()
		banned = banDataStore:GetAsync(playerUserId)

		if banned == true then
			player:Kick("You are banned! Reason:... Length:...")
		end
	end)
end)

I have described some script lines so you can understand this script better.
I would appreciate any help.

You could use os.date() for that.

1 Like

I have never used os.date() before could you explain it to me please?

os.date() returns the number of seconds since January 1, 1970, 12:00 AM UTC.

1 Like

Edit: Its actually os.time() Sorry for the confusion. This thread can help you.
https://developer.roblox.com/en-us/api-reference/lua-docs/os

1 Like

Days are 86,400 seconds, hours are 3,600 seconds and minutes are of course, 60 seconds.

os.time() returns the time (in seconds) that have elapsed since the unix epoch (January 1st 1970 00:00:00).

Store the value this function returns with bans, then when you need to query how many seconds have passed since a ban simply subtract os.time() by the time stored with the ban.

3 Likes

I am trying to script that right now, I will tell you if it works or not.

You could just take a model from it. Like mine.

You can change it to whatever time you want.

should I use this to make the script know how long days, hours and minutes are?

local Days = math.floor(seconds / 86400)
	local Hours = math.floor(math.modf(seconds,86400)   / 3600)
	local Minutes = math.floor(math.modf(seconds,3600)   / 60)

but I dont know how to solve this error.

orangew

Everytime I try to use the ban-panel it says:
error

math.modf takes one position argument.

https://developer.roblox.com/en-us/api-reference/lua-docs/math

1 Like