How would I make a player be temp banned?

Im making a game where when you die you lose max health and when you get a kill you gain health.
Code:

local Players = game:GetService("Players")

local DEFAULT_HEALTH = 100
local MINIMAL_MAX_HEALTH = 10

local template = Instance.new('Folder') do
	template.Name = 'leaderstats'
	local kills = Instance.new('IntValue')
	kills.Name = 'Kills'; kills.Parent = template
	local deaths = Instance.new('IntValue')
	deaths.Name = 'Deaths'; deaths.Parent = template
end

local playerMaxHealth = {}

Players.PlayerAdded:Connect(function(player)
	local leaderstats = template:Clone()
	leaderstats.Parent = player

	local kills = leaderstats.Kills
	local deaths = leaderstats.Deaths

	local currentCharacter

	playerMaxHealth[player] = DEFAULT_HEALTH

	player.CharacterAdded:Connect(function(character)
		if currentCharacter then currentCharacter:Destroy() end
		currentCharacter = character

		local humanoid = character:WaitForChild('Humanoid')
		humanoid.MaxHealth = playerMaxHealth[player]
		humanoid.Health = playerMaxHealth[player]

		humanoid.Died:Once(function()
			deaths.Value += 1

			if playerMaxHealth[player] -10 < MINIMAL_MAX_HEALTH then
				playerMaxHealth[player] = MINIMAL_MAX_HEALTH
			else
				playerMaxHealth[player] -= 10
			end

			for _, child in ipairs(humanoid:GetChildren()) do
				if child:IsA('ObjectValue') and child.Value and child.Value:IsA("Player") then

					local killer = child.Value
					killer.leaderstats.Kills.Value += 1 -- definitely loaded
					playerMaxHealth[killer] += 10

					local killerHumanoid = killer.Character and killer.Character:FindFirstChild("Humanoid")
					killerHumanoid.MaxHealth = playerMaxHealth[killer]

					break;
				end
			end
		end)
	end)
end)

It ins server script service.
How would i make it so that when you lose all your health you get banned for 1 hour with a message?

2 Likes

When the player dies, get the current time using os.time(). Convert that into an int, and then add 3600 to that number. Once that is done, save the time to a datastore and kick the player.

Once that is done, add an on join function When the player joins, load the data. Once that data is loaded, if the time that you saved is bigger than the current os.time(), kick them again. Else if the time is smaller or there is no time, let them join

1 Like

You could set it so that when the player is banned, you save the time, and then when the player joins again (if he does), you calculate the time they were away, and unban them. The banning can be done using the Player:Kick() function preventing the player from entering the game.

Could you give an example? thx

Could you please search before posting? Thanks :smile: