Setting user's pfp when converted their name to userid

I’m attempting to set a player’s user by getting their username from a textbox, being fired from a RemoteEvent but it seems that it doesn’t function. I had to convert their user to userID, but I may not get it. Any assistance will be appreciated, here’s the script I currently have written:

game.ReplicatedStorage.Input.OnServerEvent:Connect(function(plr,txt)
    local cache = {}
    local plrs = game:GetService("Players")

local function getIDfromText(name)
    if cache[name] then return cache[name] end
    local plr = plrs:FindFirstChild(name)
    if plr then
        cache[name] = plr.UserId
        return plr.UserId
    end
    local id 
    pcall(function()
        id = plr:GetUserIdFromNameAsync(name)
end) 
cache[name] = id
return id 
end 

local function setPfp()
	getIDfromText(txt)
end

local pfp = plr.PlayerGui.Host.MainFrame.Panel.UserPFP

	pfp.Image = "https://www.roblox.com/bust-thumbnail/image?userId="..setPfp.."&width=420&height=420&format=png"

end)

The current error I obtain is: ServerScriptService.HostLoader:26: attempt to concatenate function with string

You forgot the brackets! You tried to concatenate your function instead of concatenating what was returned from it.

pfp.Image = "https://www.roblox.com/bust-thumbnail/image?userId=".. setPfp() .."&width=420&height=420&format=png"

Ah! I didn’t realise, thank you. But this error pops up now ServerScriptService.HostLoader:26: attempt to concatenate nil with string.

You need to return what is returned from getIDfromText!

local function setPfp()
	return getIDfromText(txt)
end
1 Like

Oh my, thank you so much for your assistance! I’m kind of a beginner and I may not realise these simple errors.