Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

0

Whoops! I usually never make that mistake. Thanks for pointing that out!

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.

3 comments

0

Ninja'd

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.

1

I know it probably isn't needed here, as was implied in that sentence. 'in cases where..." It was given for future reference. 

This discussion is preserved as it was. New answers, comments, and votes are closed.