I’d like to make an System meeting this requirements:
A script that automatically bans people from the game if they die or if they have taken damage from somewhere in the last 30 seconds and they log out (exit the game) , so basically they take damage and immediately after they exit the game, they should get banned!
All of this should be connected to a list where Admins from the group can unban people!
I am struggling to make this, Ive tried so many solution but nothing worked
Ive tried giving the player an bool value and saving it to a data store , and everytime he joined if the bool was true he would get kicked , but idk how to make it like i want
If you have no idea how to make a ban system, I’d suggest looking for a tutorial somewhere. I know there’s plenty tutorials for ban systems. Once you got that figured out, you can make it so it bans the player if they die or get combat-logged.
If you plan to ban the Player from the Server, you should (or can) keep track of them using tables like this:
plrHistory = {} -- table
game.Players.PlayerAdded:connect(function(plr) -- player
if plrHistory[plr.UserId] then -- if index found for players UserId
plr:Kick("You are banned") -- Kicks Player
end
end)
so then if they take damage or die, you can then kick them.
you can use Humanoid.HealthChanged for this purpose.
local Bans = {}
function Give(Character:Model?)
if not Character:FindFirstChild("Damaged") then
local Obj = Instance.new("BoolValue")
Obj.Value = true
Obj.Name = "Damaged"
Obj.Parent = Character
game:GetService("Debris"):AddItem(Obj, 30)-- should last 30 seconds
end
end
game:GetService("Players").PlayerAdded:Connect(function(Player)
if table.find(Bans, Player.UserId) or Bans[Player.UserId] then
Player:Kick("No.")
return
end
Player.CharacterAdded:Connect(function(Character)
local Humanoid = Character:FindFirstChildOfClass("Humanoid")
Humanoid.Died:Connect(function()
table.insert(Bans, Player.UserId)
Player:Kick("You have been banned because you died..")
end)
Humanoid.HealthChanged:Connect(function(HP)
Give(Character)
end)
end)
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player)
pcall(function()
if Player.Character:FindFirstChild("Damaged").Value == true then
table.insert(Bans, Player.UserId)
end
end)
end)