Ban for 12 Hours Scripting Support

Hello!

My name is Frosty and I’m currently working on a system that bans someone for 12 hours then unbans them after the timer even if the server isn’t running. I know how to ban the player and all that stuff but how can I do a wait 12 hours without the server running?

Thanks for reading.

1 Like

You can save os.time() of their ban, and when they return check if their (time - current os.time()) is > (12 * 60 * 60) [h, m, s]

1 Like

Do you have any good tutorials on that as I’m a bit confused.

Here’s some really good coverage. This just goes to show that you should search for existing answers before posting.

or save the time when the bans ends and check if that timestamp has passed, if not, kick plr
if do … delete timestamp

I did search for eisting answers as well but they only apply to one server and doesn’t ban them from every server.

So what you can do is to set up a ban datastore. Then everytime you ban them, it will add from the current time.

local DS = game:GetService("DataStoreService") 
local BanDS = DS:GetDataStore("Ban") 
local Players = game:GetService("Players") 

--Checking if they have been banned
Players.PlayerAdded:Connect(function(plr) 
	local data

	local success, Error = pcall(function() 
		data = BanDS:GetAsync(plr.UserId) 
	end) 

	if success then
		if data then
			if os.time() < data then
				--Ban has not finished 
				plr:kick("Your ban has not been completed") 
			else
				--Player Ban ended
			end
		end
	else
		warn(Error) 
	end
end) 

--Saving a ban (Put it in your ban function) 

local Success, erro = pcall(function() 
	BanDS:SetAsync(plr.UserId, os.time() + 60*60*12)
end) 
if not Success then
	warn (erro) 
end
1 Like

Thanks so much as this did work, but I have a question, what does the 60 * 60 * 12 stand for just in case I want to change the ban time.

os.time() is counted by seconds. So in order to change 12 hours into seconds, we would need to times. * means times (x). 60(seconds) * 60(minutes) * 12(hours). I hope you understand

1 Like

Alright, makes since. Thank you once again for the help.