RemoteFunction not returning correct value

Server-script

CountryFunction.OnServerInvoke = function(plr)
    local Country = require(ReplicatedStorage.CountryService):GetPlayerCountry(plr)
    print("Country of"..tostring(plr).."is ")
    print(Country.name)
    return Country
end

Returns ireland, correct country
Localscript

local targetPlayer = Players:GetPlayerByUserId(player.UserId)
    local CountryInfo = CountryFunction:InvokeServer(targetPlayer)
    print("Country of the client is: ",CountryInfo)
    frameClone:WaitForChild("CountryImage").Image = CountryInfo.decal

Returns the UK which isn’t the correct country and is the local players country instead of Ireland (correct country).

Can someone help me with this issue?

1 Like

The first argument the server receives is always the Player that invoked the function. You will actually want the second argument of the function, which will be the Player that the client sent.

CountryFunction.OnServerInvoke = function(sendingPlayer, checkPlayer)
    local Country = require(ReplicatedStorage.CountryService):GetPlayerCountry(checkPlayer)
    print("Country of"..tostring(checkPlayer).."is ")
    print(Country.name)
    return Country
end
1 Like