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

unpack() printing out only first word?

I've been attempting to make my own /name script. It's been going fine until this happened: https://gyazo.com/eb1732b08734164f26089b2fd6d2190a

Here's the line of code that changes the text:

local function NameChange(player, text)
	local character = player.Character
	character.Head.RPName.Text.Text = unpack(text)
	print(unpack(text))
end

Help?

1 comment

0

This script is located in ServerScriptService for anyone who's interested

1 answer

✓ Accepted answer

This isn't an issue with the script, but actually with how unpack works...

Essentially, for a lot of functions in roblox, they can have multiple returns, such as game.Workspace:FindPartOnRay(...), which returns a part, a hit position, and a part normal.

This works on a very similar concept. Essentially, it's returning an entire list of table elements, but print can only accept one when put in that format, so it'll appear as if it's not unpacking the entire table. In reality, the print just excludes the other elements outside the very first, making this issue appear as such.

Please leave any comments, corrections, or any suggestions on what to add in the comments below.

Edit: It was requested that I also show a method of combining a table of strings into a single string:

local StringThing
for _,v in pairs(StringTable) do
	StringThing = StringThing .. v
end
print(StringThing)

6 comments

0

Okay, so what would be a good alternative to this.

0

Depends, how is text stored? I'm assuming you just want to combine a bunch of strings into one

0

Exactly, a table to a string.

0

Let me quickly modify this answer to show a method of combining a table of strings then.

0

Did it work?

0

Additionally, upvoting helps me out for something.

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