Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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 :)

1 comment

0

check below

1 answer

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)

4 comments

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?

0

I don't understand what you mean with table.insert? You can manualy type the names into the AllowedIn list.

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 :)

0

you can just use a function like function Add(ID) AllowedIn[ID] = true end

This discussion is preserved as it was. New answers, comments, and votes are closed.