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

unpack() printing out only first word?

Asked by 3 years ago

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?

0
This script is located in ServerScriptService for anyone who's interested loowa_yawn 383 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited 3 years ago

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)
0
Okay, so what would be a good alternative to this. loowa_yawn 383 — 3y
0
Depends, how is text stored? I'm assuming you just want to combine a bunch of strings into one animorphs30 300 — 3y
0
Exactly, a table to a string. loowa_yawn 383 — 3y
0
Let me quickly modify this answer to show a method of combining a table of strings then. animorphs30 300 — 3y
View all comments (2 more)
0
Did it work? animorphs30 300 — 3y
0
Additionally, upvoting helps me out for something. animorphs30 300 — 3y
Ad

Answer this question