01 | local selected = { } |
02 |
03 | mouse.Button 1 Down:Connect( function () |
04 | local team = game.Workspace:WaitForChild(player.TeamColor.Name) |
05 | if team then |
06 | if mouse.Target:IsDescendantOf(team) then |
07 | table.insert(selected,mouse.Target.Parent) |
08 | print ( unpack (selected)) |
09 | end |
10 | end |
11 | end ) |
Basically if what is selected is member of team it inserts it into the table but when you select it again it inserts a second copy into the table. How can I see if its already in the table? thanks.
make a loop that goes through all the table values(or copy my code):
1 | local function checkintable(table, object) -- put in your table and the object you are looking for |
2 | for i = 1 , #table do -- change the one to zero if your first place in the array is at 0 |
3 | if table [ i ] = = object then |
4 | return true |
5 | end |
6 | end |
7 | return false -- make a variable that calls this function and then add an "if then" statement saying if it returns false, then add it into the table. |
8 | end ) |