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

Inserting players into Table using touched event

So, how would I be able to do it?

Admins = {}

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
--What now? :)
end
end)

Also, how would I check if the player that touched it is already in the table so there is no duplicate player entries?

2 answers

✓ Accepted answer
Admins[hit.Parent.Name]=game.Players:GetPlayerFromCharacter(hit.Parent)

This will insert their name as a key into the table with their player as the value. There can't be duplicate keys in the same table.

This goes through the admin table and checks for their name. If it's already there, nothing happens. If not, then it inserts their name into the admin table. Untested so not sure if it works.

for i, v,in pairs(Admins) do
if.hit.Parent.Name == i then
print("already in table")
elseif hit.Parent.Name == nil then
table.insert(Admins, hit.Parent.Name)
end
end

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