local frame = script.Parent:WaitForChild("Frame") local names = {"Player1", "14dark14"} wait(3) player = game.Players.LocalPlayer if player.name == names then script.Parent.Enabled = true else script.Parent:Destroy() print("no") 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
local frame = script.Parent:WaitForChild("Frame") local names = {"Player1", "14dark14"} wait(3) player = game.Players.LocalPlayer for i, v in pairs(names) do if player.Name == v then script.Parent.Enabled = true return end end script.Parent:Destroy() print("no")
(I think) it's because you need to specify which name it is just like so:
local frame = script.Parent:WaitForChild("Frame") local names = {"Player1", "14dark14"} wait(3) player = game.Players.LocalPlayer if player.name == names[1] or names[2] then script.Parent.Enabled = true else script.Parent:Destroy() print("no") 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().
local frame = script.Parent:WaitForChild("Frame") local names = {"Player1", "14dark14"} wait(3) player = game.Players.LocalPlayer for i, v in pairs(names) do if player.Name == v then script.Parent.Enabled = true end 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:
local Players = game:GetService("Players") local player = Players.LocalPlayer local names = {"Player1", "14dark14"} local foundName = false for _, name in pairs(names) do if name == player.Name then foundName = true break end end if foundName then script.Parent.Enabled = true else script.Parent:Destroy() 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:
local frame = script.Parent:WaitForChild("Frame") local names = {"Player1", "14dark14"} wait(3) player = game.Players.LocalPlayer if names[player.Name] then script.Parent.Enabled = true else script.Parent:Destroy() print("no") 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