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

Is a variable tied to an instance or is a variable simply pointing to an instance name?

So, I am curious

local part1 = Insance.New("Part")
part1.Name = "Part"
local part2 = Insance.New("Part")
part2.Name = "Part"
local part3 = Insance.New("Part")
part3.Name = "Part"
part2:Destroy()

will lua get confused by this? will it destroy a random part? i tried printing the vars but it just says "part" so my question is, is part1 variable tied to the part it created or is it just pointing at the name? also, when i destroy part2 will the variable simply be set to nil?

2 comments

0

variables are tied to individual objects so if you destroy() part2 only part2 will be destroyed

0

It isn't lua that is confused, it is I, why did you give the .Name property, seems totally random as well as use "Insance" instead of Instance.

1 answer

Lua will not get confused by this. The variables, in this case, are pointing to the object; It will not matter if they are all given the same name.

When you print the object, it does print the name. However, you should be able to click on the name in the output, and it would open up the hierarchy for that object in the explorer.

It would be different if you were using the variable to search for an object. Let us say you had multiple parts in the workspace with the same name (e.g. "Part"); if you were to try and get an object named 'Part' from the workspace, it would only return the first one it finds.

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