Script for plugin not working

I am currently working on a load character plugin. I have a slight problem tho: the image is not being showed when you type in the name for the character you want to be loaded in. It works for the first time but not the second, third, etc.

Here is the script:
while wait() do
local Players = game:GetService(“Players”)

    local cache = {}

    function getUserIdFromUsername(name)
        if cache[name] then return cache[name] end
        local player = Players:FindFirstChild(name)
        if player then
            cache[name] = player.UserId
            return player.UserId
        local id
        pcall(function ()
            id = Players:GetUserIdFromNameAsync(name)
        cache[name] = id
        return id
    local namebox = script.Parent.Parent.NameBox.Text
    local name = getUserIdFromUsername(namebox)
    script.Parent.Image = "

The error is on the 24th line, the error is the following:
This is the error: attempt to concatenate string with nil

If anybody knows how to fix this or why its not working, please tell me in the replies!

script.Parent.Image = "

This endpoint is deprecated (maybe even discontinued) and doesn’t have the right arguments. UserId should be equal to the user you’re looking up.

Instead of using the direct endpoint, you could instead use the rbxthumb protocol to get the user image.
It would look something like this:

script.Parent.Image = "rbxthumb://type=AvatarHeadShot&id=UserId&w=150&h=150"

You should also consider cleaning your script, there’s no need to use a while true do loop, you can just run the code when the textbox’s text is changed (which means the player typed something)

1 Like

Thanks, i will see if it works!

hey, i tried it it does not seem to be working.

Make sure to replace “UserId” with the id of the player you want to fetch the thumbnail.

1 Like

Its giving the same error as before, but its also saying that the request from the image has failed.

nevermind, its working now! Thank you.