I have this code but this didn't work at all. Example code:
1 | local ExampleTable = { "Player1Name" , "Player2Name" } |
2 |
3 | script.Parent.MouseButton 1 Click:Connect( function () |
4 | if ExampleTable [ game.Players.LocalPlayer.Name ] then |
5 | --Do this |
6 | else |
7 | --Do this |
8 | end |
9 | end ) |
Im basically trying to see if a player's name is inside of my local table.
A table (known as an array in most programming languages) is a list of values (which you already know) called elements. To set/read data from the table you use the following format Table[i] where i is the spot in the table you wish to set or read. so what you want is something like this
1 | for i,v in ipairs (ExampleTable) do |
2 | if v = = game.Players.LocalPlayer.Name then |
3 | --Do this |
4 | else |
5 | --Do this |
6 | end |
7 | end |
i counts how many elements in the table it has found and v is the value of the element it is checking.