Detecting if a user has the same stringvalue value

Hi, how can I detect whether or not another user has the same value as someone else? I’d greatly appreciate the help! I’m assuming that I’ll need to loop through all of the players.

You’re correct that you have to loop through players. Here’s a simple implementation.

-- Server
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(value) 

    if value == true then
        print("The players have the same value")
    else 
        print("The players don't have the same value")
    end

end)

-- Client

-- Say this is in a TextButton
local players = game.Players:GetChildren()

script.Parent.MouseButton1Click:Connect(function(plr)

    for i,v in pairs(plrs) do
        if v.leaderstats.StringValue.Value == plr.leaderstats.StringValue.Value then
            print("Comparing "..[plr.Name].." and "..[v.Name]
            game.ReplicatedStorage.RemoteEvent:FireServer(true)
        else 
            game.ReplicatedStorage.RemoteEvent:FireServer(false)
        end
    end

end)
1 Like