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

How can I compare values from a table?

Asked by 5 years ago

I'm completely new to tables so I have no Idea what I'm doing with this script, but I'm re making a script for admins that will give anyone with the name of an admin a tool.

local admins = {"darkblooood"}

game.Players.PlayerAdded:Connect(function(player)
if admins == player.Name then
    print(player.Name)
end
end)

2 answers

Log in to vote
0
Answered by
iSvenDerp 233 Moderation Voter
5 years ago

Hi, hope this helps! You're going to need the put the name of your tool in serverstorage, because we will clone the tool into the players backpack. Put this server script in workspace.

local admins = {"darkblooood", "AnotherAdmin", "Adminsusername"} 
local gear = game.ServerStorage.Toolnamehere -- This creates a variable for your tool in server storage(Make sure to rename toolnamehere to your tool name)

game.Players.PlayerAdded:Connect(function(plr)
         plr.CharacterAdded:Connect(function(chr)
              for i = 1, #admins do
                   if admins[i] == plr.Name then
                        gear:Clone().Parent = plr:WaitForChild("Backpack")
                    end
              end
       end)
end)   

Let me know if you have any questions, and feel free to accept if it helped! It should work!

0
Don't remind users to accept your answer. If it truly helped, it is nature for them to accept it. You're just being greedy. User#19524 175 — 5y
Ad
Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

To make comparisons to items in a table, you simply loop through the table and compare each individual item using a for loop.

Here's an example:

local player = game.Players.LocalPlayer

local examplePlayer = "darkblooood"
local exampleTable = {"item1", "apple", examplePlayer}

for i, exampleItem in pairs(exampleTable) do
-- syntax for this loop is:
-- for [index variable name], [value variable name] in pairs([table name]) do
    if player.Name == exampleItem then
        print(player.Name)
    end
end

Hope this helps :)

Answer this question