01 | local frame = script.Parent:WaitForChild( "Frame" ) |
02 | local names = { "Player1" , "14dark14" } |
03 | wait( 3 ) |
04 | player = game.Players.LocalPlayer |
05 | if player.name = = names then |
06 | script.Parent.Enabled = true |
07 | else |
08 | script.Parent:Destroy() |
09 | print ( "no" ) |
10 | end |
printed no even tho my name is 14dark14
The answer by zamd157 would work. But if your table would grow in the future then it would get messy and unorganized to write it out. The best to do is to loop through your table
01 | local frame = script.Parent:WaitForChild( "Frame" ) |
02 | local names = { "Player1" , "14dark14" } |
03 | wait( 3 ) |
04 | player = game.Players.LocalPlayer |
05 | for i, v in pairs (names) do |
06 | if player.Name = = v then |
07 | script.Parent.Enabled = true |
08 | return |
09 | end |
10 | end |
11 |
12 | script.Parent:Destroy() |
13 | print ( "no" ) |
(I think) it's because you need to specify which name it is just like so:
01 | local frame = script.Parent:WaitForChild( "Frame" ) |
02 | local names = { "Player1" , "14dark14" } |
03 | wait( 3 ) |
04 | player = game.Players.LocalPlayer |
05 | if player.name = = names [ 1 ] or names [ 2 ] then |
06 | script.Parent.Enabled = true |
07 | else |
08 | script.Parent:Destroy() |
09 | print ( "no" ) |
10 | end |
Hello! 'names' is an entire table, not just a string. That's why your code didn't work, to make this work, what you have to do is get everything in the table, so using for i, v in pairs().
1 | local frame = script.Parent:WaitForChild( "Frame" ) |
2 | local names = { "Player1" , "14dark14" } |
3 | wait( 3 ) |
4 | player = game.Players.LocalPlayer |
5 | for i, v in pairs (names) do |
6 | if player.Name = = v then |
7 | script.Parent.Enabled = true |
8 | end |
9 | end |
This way its not messy and it works, accept if was helpful, otherwise tell me so
You're comparing the name of the player to a table.
Line 02 is the table and on line 05 you access the Name
property which gives you a string.
You need to index the table to read the value of each element.
You can do this with a for-loop to linearly search for a value in the 'names' table:
01 | local Players = game:GetService( "Players" ) |
02 |
03 | local player = Players.LocalPlayer |
04 |
05 | local names = { "Player1" , "14dark14" } |
06 |
07 | local foundName = false |
08 |
09 | for _, name in pairs (names) do |
10 | if name = = player.Name then |
11 | foundName = true |
12 | break |
13 | end |
14 | end |
15 |
16 | if foundName then |
17 | script.Parent.Enabled = true |
18 | else |
19 | script.Parent:Destroy() |
20 | end |
I recommend that you learn more about the basics of Lua. Specifically, loops and tables as these are concepts that will help you become a better programmer:
01 | local frame = script.Parent:WaitForChild( "Frame" ) |
02 | local names = { "Player1" , "14dark14" } |
03 | wait( 3 ) |
04 | player = game.Players.LocalPlayer |
05 | if names [ player.Name ] then |
06 | script.Parent.Enabled = true |
07 | else |
08 | script.Parent:Destroy() |
09 | print ( "no" ) |
10 | end |
i thought ur destroying it then printing it but idk someone in comments tell me why but that's not how u check through tables