Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Attempt to concatenate upvalue 'username' (a userdata value)?

Asked by 9 years ago
local frame = script.Parent.Parent
local inputbox = frame:WaitForChild("TextBox")
local holder = frame.Parent
local display = holder:WaitForChild("display")
local imagelabel = display:WaitForChild("ImageLabel")

local userimg = 'http://www.roblox.com/Thumbs/Avatar.ashx?format=png&x=100&y=100&username='

local username = frame:WaitForChild("username")

script.Parent.MouseButton1Click:connect(function()
    username.Value = inputbox.Text
    wait()
    imagelabel.Image = userimg..username
end)

I'm currently working on a search system that relies on user input. Why can't it link username to userimg?

2 answers

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

Your problem is that username is an object, not a string and you tried to concatenate it.

Silly mistakes(:

So to fix? Concatenate the value of username.

local frame = script.Parent.Parent
local inputbox = frame:WaitForChild("TextBox")
local holder = frame.Parent
local display = holder:WaitForChild("display")
local imagelabel = display:WaitForChild("ImageLabel")

local userimg = 'http://www.roblox.com/Thumbs/Avatar.ashx?format=png&x=100&y=100&username='

local username = frame:WaitForChild("username")

script.Parent.MouseButton1Click:connect(function()
    username.Value = inputbox.Text
    wait()
    imagelabel.Image = userimg..username.Value --Index the value right here
end)
0
Whoops! I usually never make that mistake. Thanks for pointing that out! dirty_catheter 7 — 9y
Ad
Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

As far as I can tell, username is a value object, and you can't concatenate an object.

You need to get its value or name or some other useful property so that you can properly combine strings.

userimg..username.Value
--or
userimg..username.Name
--or some other property

You also might want to look into the tostring() method in cases where you need to convert something into a string before concatenating.

0
Ninja'd Goulstem 8144 — 9y
0
Also, the tostring function isn't needed here. Username.Value is going to be a StringValue or else it wouldn't ever work. Concatenating strings with numbers in them is fien. Goulstem 8144 — 9y
1
I know it probably isn't needed here, as was implied in that sentence. 'in cases where..." It was given for future reference.  Perci1 4988 — 9y

Answer this question