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

Offices, need kill brick for unauthorized users, any ideas?

Asked by 5 years ago

I am making offices for my game for the HR ranks, i have a table of whitelisted people which can be added to by a gui, my problem is this bit of code here:

for i,v in pairs(owner) do
    script.Parent.Parent.unauthkill.Touched:Connect(function(tch)
    if tch.Parent:FindFirstChild("Humanoid") then
        if tch.Parent.Name ~= v then       
            tch.Parent:FindFirstChild("Humanoid").Health = 0
        end
    end
end)

this is supposed to kill anyone who isn't in the table "owners" (whitelisted) but insted, if there are two people in the table, let's say "PersonA" and "PersonB", PersonA wil be fine but the script will kill "PersonB" because in the eyes of the script, PersonA is not PersonB

Does anyone know how to make it check all users of a table first and then take action? If you do I would be great full if you could help :)

0
check below RubenKan 3615 — 5y

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago

If you'd have a table with all the names put in using the Dictionary style of tables, it's extremely easy.

local AllowedIn = {
    ["Username"] = true,
    ["3923232"] = true 
    -- userid or username
}

--Touch function
Object.Touched:Connect(function(Hit)
    --Get player from character if a character touched the part
    local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
    --check if their name or userid is in the dictionary
    if Player and not (AllowedIn[Player.UserId] or AllowedIn[Player.Username]) then
    Player.Character:BreakJoints()
    end
end)
0
That would be awesome, but then i run into the issue of table.insert when you come to whitelist player, would it insert as a dictionary? Radobskii 0 — 5y
0
I don't understand what you mean with table.insert? You can manualy type the names into the AllowedIn list. RubenKan 3615 — 5y
0
^ It's because I want players to be whitelisted and added to the table from in-game, however I took your answer into consideration and adapted it and it worked! Thank you :) Radobskii 0 — 5y
0
you can just use a function like function Add(ID) AllowedIn[ID] = true end RubenKan 3615 — 5y
Ad

Answer this question