This should work for everything you’ve asked so far,
hope this helps!
local Players = game.Players
local Template = Instance.new 'BoolValue'
Template.Name = 'leaderstats'
Instance.new('IntValue', Template).Name = "Kills"
Instance.new('IntValue', Template).Name = "Deaths"
Instance.new('IntValue', Template).Name = "Health"
local DataStoreService = game:GetService("DataStoreService")
local BanDataStore = DataStoreService:GetDataStore("Ban")
local function kickPlayer(player)
player:Kick("Come back in an hour after the ban") -- this contains the ban message
end
local function banPlayer(player, durationInHours)
local banExpires = os.time() + durationInHours * 3600
local success, result = pcall(function()
BanDataStore:SetAsync(tostring(player.UserId), banExpires)
end)
if not success then
warn("Error saving ban status for player " .. player.Name .. ": " .. tostring(result))
else
kickPlayer(player)
end
end
Players.PlayerAdded:connect(function(Player)
Instance.new('BoolValue', Player).Name = "Banned"
local success, banExpires = pcall(function()
return BanDataStore:GetAsync(tostring(Player.UserId))
end)
if not success then
warn("Error checking ban status for player " .. Player.Name .. ": " .. tostring(banExpires))
return
end
local currentTime = os.time()
if banExpires and banExpires > currentTime then
kickPlayer(Player)
end
wait(1)
local Stats = Template:Clone()
Stats.Parent = Player
local Deaths = Stats.Deaths
local join = true
Player.CharacterAdded:connect(function(Character)
local Humanoid = Character:FindFirstChild "Humanoid"
Stats.Health.Value = Humanoid.MaxHealth
if Humanoid then
Humanoid.Died:connect(function()
for i, Child in pairs(Humanoid:GetChildren()) do
if Child:IsA('ObjectValue') and Child.Value and Child.Value:IsA('Player') then
local Killer = Child.Value
if Killer:FindFirstChild 'leaderstats' and Killer.leaderstats:FindFirstChild "Kills" then
local Kills = Killer.leaderstats.Kills
local Health = Killer.leaderstats.Health
Kills.Value = Kills.Value + 1
Health.Value = 100
Humanoid.MaxHealth = Kills.Value*10+100 - Deaths.Value*10
Health.Value = Health.Value + 10
end
return
end
end
end)
end
if join then join = false return end
Deaths.Value = Deaths.Value + 1
Player.Banned.Value = true
banPlayer(Player, 1)
end)
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, result = pcall(function()
BanDataStore:SetAsync(tostring(player.UserId), player.Banned.Value)
end)
if not success then
warn("Error saving ban status for player " .. player.Name .. ": " .. tostring(result))
end
end)