Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

This discussion is preserved as it was. New answers, comments, and votes are closed.