Answered by
6 years ago Edited 6 years ago
Hey Marmalados,
You can not concatenate instances. Concatenation is a process only used for strings. You might be wondering how then can you print the instances. Well, let me take the time to explain how it works.
OOP Review
A part is just an object made through a class defined.(This is called OOP, when you orient the program through objects: Object Oriented Programming) When you try to print an object that is created through the class, it tries to convert the instance to a string. In order to do this, it looks for the str method(Python), or basically the method that is supposed to return the string representation of the object.
What Roblox did with this method is just return the name of the object. So, if you try to do something like this:
part = workspace.Part
part2 = workspace.Part2
var1 = tostring(part)
var2 = tostring(part2)
print(var1) -- Prints: Part
print(var2) -- Prints: Part2
They just convert the part to a string, and that string is the name of the object.
Solution
So, as you may see above, you can get their string representation by converting them to strings. After doing so, you can easily concatenate them. Something like this:
part = workspace.Part
part2 = workspace.Part2
var1 = tostring(part)
var2 = tostring(part2)
print(var1..var2) -- Prints: PartPart2
Conclusion
The reason the print method works with instances is that it gets the string representation of the instance, which Roblox has put as the name of the object. You can only concatenate strings. I hope i helped and have a wonderful day.
Thanks,
Best regards,
KingLoneCat