how to make script that ban players if they die
1 Like
Something like the script below however it will also need a datastore component for ban persistence throughout multiple servers which you will need to implement yourself.
There should be an article below on how to use datastores as well.
2 Likes
Use data stores and remote events.
1 Like
dthecoolest made the solution btw and this is the code if you dont understand
,
local DataStoreService = game:GetService("DataStoreService") -- Service
local Data = DataStoreService:GetDataStore("BannedPlayers") -- Data
game.Players.PlayerAdded:Connect(function(Player) -- Getting da player
Player.CharacterAdded:Connect(function(Character) -- Getting da character
if Data:GetAsync(Player.UserId) == false then -- Confirming if the player is banned by boolean (false is obv...NOT)
Character.Humanoid.Died:Connect(function() -- Function for the player dies
Data:SetAsync(Player.UserId, true) -- Setting the data to true
Player:Kick("REASON HERE") -- Kicking him
end)
else -- da opposite and it supposed to be true cuz boolean has only 2 values
Player:Kick("REASON HERE") --
end
end)
end)
DO NOT USE THIS SCRIPT ALRIGHT IT JUST DOES WHAT IT DOES OK SO NO DONT USE IT
game.Players.PlayerAdded:Connect(function(Player)
if game.DataStoreService:GetDataStore("BanOnDeath"):GetAsync(Player.UserId) then
Player:Kick("You have been banned for dying")
end
Player.Character.Humanoid.Died:Connect(function() game.DataStoreService:GetDataStore("BanOnDeath"):SetAsync(Player.UserId, os.time())
end)
end)
I am serious when i mean this likely wont work. the most il give is a painfully barebones highly fragile script that I would like you to work on, wrap in pcalls, retries, using updateasync, etc in order to learn!
1 Like