Game join cooldown

Greetings, community. I’m currently making an application centre. However, I want to prevent people from spamming the application by adding a join cooldown for 12 hours. So when someone joins and leaves, they’re basically being banned from the game for 12 hours and after 12 hours, they will be unbanned and able to join the game again. How do I implement this?

2 Likes

Use os.time + DataStorage, every time a player enters, check the date he joined if it has been less than 12 hours since he joined, kick it, then if he is admitted, save that new login.

1 Like

Could you elaborate more about DataStores and os.time()? I don’t really understand datastores unfortunately.

Give me one second I’ll create a basic example for you.

1 Like

Here is my somewhat basic example. There are ways to make it more effective but I just went for the easiest I could do in less time. Just change the 43200 to the amount of seconds you want them to be banned for. currently its set for 12 hours.

local db = game:GetService("DataStoreService"):GetDataStore("-datastorename-")

game.Players.PlayerAdded:Connect(function(player)
	local isBan = db:GetAsync(player.UserId.." IsBanned")
	local banTime = db:GetAsync(player.UserId.." IsBanned Time")
	local timeFromNow = tonumber(os.date("%S",banTime))
	if isBan == true then
		if os.time()-banTime >= 43200  then
			db:SetAsync(player.UserId.." IsBanned",false)
		else
			player:Kick("Nope")
		end
	else
		db:SetAsync(player.UserId.." IsBanned",true)
		db:SetAsync(player.UserId.." IsBanned Time",os.time())
	end
end)
2 Likes