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?