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

How to check if a string is in a table?

Asked by
RedCombee 585 Moderation Voter
10 years ago

In my admin script, I need to find out if the player who is chatting is listed in the table or not. Is there some type of string function that can be used to search a table?

0
I have my own admin script. ;D Gravity Admin(S) Im working on my next generation admin commands! So if you need some help just message @jillmiles1 on ROBLOX. MessorAdmin 598 — 10y

2 answers

Log in to vote
0
Answered by 10 years ago
local Admins = {"RedCombee"}

local function CheckIfAdmin(Player)
    for _,adminName in pairs(Admins) do
        --What this does is makes it so "adminName" is the words in the table Admins
        if Player.Name == adminName then  --If the player's name is the same as adminName, then:
            return true
        else --Anything else except if the player's name is the same as adminName
            return false
        end
    end
end

for _,player in pairs(game.Players:GetPlayers()) do
    --What this does it makes it so "player" is every player in the game
    player.Chatted:connect(function(message)
        if CheckIfAdmin(player) == true then --calls the function we made earlier
            --CODE HERE :)
        end
    end)
end
Ad
Log in to vote
-1
Answered by 10 years ago

*Heres a TIP not a "answer" but this will get your started on the correct path ;D*

Table={'RedCombee','MessorAdmin','idjwijwdiwjdiwidjwidwidj'};

function G(Plr)
for _,v in pairs(Table) do
print(v)
if v==Plr:lower() or v==Plr.Name:lower() then
print(Plr)
end

G(game.Players.RedCombee)

Answer this question