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

I cant get my if loop to check if a string from a table is the same as another value?

Asked by 6 years ago

Hi Guys,

So Im using RemoteFunctions to send the player name to a serverscript. The server script has a table of strings that are player names. Ive checked and confirmed that the for loop is iterating through the table and that the player name is also correct. any help please?

checkRF = game.ReplicatedStorage.ReportAPI_Config.CheckAdmin
AuthorisedUsers = {"ff","test1","test","t","MrTomasboy","h"}

function CheckTable(plr)
    for i,v in pairs(AuthorisedUsers) do
        if v == plr then
            print("MATCH FOUND")
            return plr
        else
            print("NO MATCH")
        end
    end
end

checkRF.OnServerInvoke = CheckTable

1 answer

Log in to vote
0
Answered by
HaveASip 494 Moderation Voter
6 years ago
Edited 6 years ago

You have two problems. First on the line 6. You cant equal string to the object, so you need to change code on that line. Second is that you set your function activating incorrect on the last line. Here is the correct code

checkRF = game.ReplicatedStorage.ReportAPI_Config.CheckAdmin
AuthorisedUsers = {"ff","test1","test","t","MrTomasboy","h"}

function CheckTable(plr)
    for i,v in pairs(AuthorisedUsers) do
        if v == plr.Name then
            print("MATCH FOUND")
            return plr
        else
            print("NO MATCH")
        end
    end
end

checkRF.OnServerInvoke:Connect(CheckTable)

I think it will be working.

P.S sorry for my english. I hope you understand what I mean

Ad

Answer this question