How do I create a block that will kill those who step on it except those who are whitelisted

I wish to know how I can script a block that will kill everyone upon stepping on it except those who are whitelisted inside of the script.

For example I wish to whitelist myself so when I step on the block I don’t die, but if someone that isn’t they would die.

I think you get the point hence there’s no point in further explanation, thanks for understanding.

Do you already know who’s on the whitelist or do you need the players added to the whitelist depending on who the player wants

Make a table for whitelisted people, and loop through table to find if player who stepped are included in whitelist table or not.

local Whitelist = {"Player1", "Player2", ...}

[BasePart].Touched:Connect(function(Part)
    if Part:FindFirstAncestorOfClass("Model") and game.Players:GetPlayerFromCharacter(Part:FindFirstAncestorOfClass("Model")) then
        local WhiteListed
        for i, v in next, game.Players:GetChildren() do
            if v.Name == game.Players:GetPlayerFromCharacter(Part:FindFirstAncestorOfClass("Model")).Name then
                WhiteListed = true
            end
        end
        if not WhiteListed then
            game.Players:GetPlayerFromCharacter(Part:FindFirstAncestorOfClass("Model")).Humanoid.Health = 0
        else
            return
        end
    end
end)
1 Like
local part = script.Parent

local whitelist = {
    "Expistic", --Names in list format go here
}

part.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
        for i,v in pairs(whitelist) do
            if v ~= hit.Parent.Name then
                hit.Parent.Humanoid.Health = 0
            end
        end
    end
end)