Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make a ondeath script that bans the player?

Asked by 4 years ago

I would like to make a game that when you die you get banned so it really feels like you are dead. I have no idea how to do this and turned over to here. I've looked on the tool box and found some but they did not work. It would be very helpful if someone could help me out or if someone could point me into the right direction to find the resources I need to accomplish this.

0
Please at least explain, a part touched that bans the player or it kills the player then after I respawns it bans? SharkOwen_dev 69 — 4y
0
When the player dies they get banned not after they die and respawn. MisterPhilo -3 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

It's pretty simple to ban a player. And even simpler to run a function when they die.

Here are 2 examples.

Example #1: Server Ban on Death

local banList = {}

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")

        humanoid.Died:Connect(function()
            table.insert(banList, player.Name)
            player:Kick()
        end)
    end)

    for _,v in next, banList do
        if player.Name == v then
            player:Kick("Banned from server.")
        end
    end
end)

Example #2: Permanent Ban on Death

local dataStoreService = game:GetService("DataStoreService")
local banData = dataStoreService:GetDataStore("BanData")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local humanoid = character:WaitForChild("Humanoid")

        humanoid.Died:Connect(function()
            banData:SetAsync(player.UserId, true)
            player:Kick()
        end)
    end)

    if banData:GetAsync(player.UserId) == true then
        player:Kick("Banned from game.")
    end
end)

So in both examples it works pretty much the same, a player enters the game then the script waits for the character to be added. After that it waits for the humanoid in the character and when the script detects that the humanoid has died it will run the code. In Example #1, it just adds their name to a table then searches for it when they enter the game again. If found, it kicks them. But in example #2, it changes a data store value to TRUE and when it detects a new player in the game it checks if that value is true and if it is, it kicks them aswell.

For more on Data Store click here.

Ad

Answer this question