String Value Error

I’m sure I’m missing something obvious but I’m getting a string value error in this script.

Players.PlayerAdded:Connect(function(NewPlayer)
    local ShortName = FindTeam(tostring(NewPlayer.Team))
    local Rand = math.random(1000,9999)
    if ShortName then
        text.Text = ''ShortName'-'Rand''     <------- Here's the line with the error
    end
end)

you are missing concatenation use two periods to concatenate.

Not sure what exactly you’re trying to do there.
I’m guessing that you want to combine those values into a single string of text, in which case use 2 dots for concatenation. Example:

ShortName .. '-' .. Rand
1 Like

I tried that and I got an “Incomplete statement: expected assignment or a function call” error.

Is it the same line? Also could you please send your current script?

Yes, here’s the script:

Players.PlayerAdded:Connect(function(NewPlayer)
	local ShortName = FindTeam(tostring(NewPlayer.Team))
	local Rand = math.random(1000,9999)
	if ShortName then
		text.Text = ''ShortName..'-'..Rand''
	end
end)
Players.PlayerAdded:Connect(function(NewPlayer)
    local ShortName = FindTeam(tostring(NewPlayer.Team))
    local Rand = math.random(1000,9999)
    if ShortName then
        text.Text = ShortName..'-'..tostring(Rand)
    end
end)

This should work if there are any errors it’s because something is not right outside this scope.

What does FindTeam return?
What is this variable “text”?

1 Like
Players.PlayerAdded:Connect(function(NewPlayer)
	local ShortName = FindTeam(tostring(NewPlayer.Team))
	local Rand = math.random(1000,9999)
	if ShortName then
		text.Text = ShortName.."-"..Rand
	end
end)

In future, when use speech marks instead of quotation marks (double instead of single) as they’re clearer. Also in Lua the concatenation operator is “…” a pair of two consecutive periods/dots, with their purpose being to join strings together, be it literal strings such as “abc”…“xyz” or variables which store string values such as var1…var2 if you need any further assistance, let me know.