So I used AI to generate this code for me bc my method was too complicated and would take up too many variables and lines but pretty what I am trying to achieve is that if the player is killed 5 times within 30 seconds then they will lose their admin perms (I am making a kohl’s admin house remake)
Code
local kickThreshold = 5 -- Number of deaths required for kick
local timeThreshold = 30 -- Time window in seconds
local kickMessage = "You've been kicked for dying too many times within a short period."
local deathCount = {} -- Table to store death counts for each player
-- Function to handle player death
local function onPlayerDeath(player)
local playerId = player.UserId
-- Initialize death count if not already present
deathCount[playerId] = deathCount[playerId] or { count = 0, lastDeathTime = tick() }
-- Check if the last death occurred within the time threshold
local currentTime = tick()
if currentTime - deathCount[playerId].lastDeathTime <= timeThreshold then
-- Increment death count
deathCount[playerId].count = deathCount[playerId].count + 1
-- Check if death count exceeds threshold
if deathCount[playerId].count >= kickThreshold then
-- Kick player
player:Kick(kickMessage)
end
else
-- Reset death count
deathCount[playerId].count = 1
end
-- Update last death time
deathCount[playerId].lastDeathTime = currentTime
end
-- Connect the function to the player death event
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
onPlayerDeath(player)
end)
end)
end)