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

Inserting players into Table using touched event [closed]

Asked by 10 years ago

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?

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago
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.

Ad
Log in to vote
1
Answered by 10 years ago

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