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

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

Asked by 1 year ago

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"

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?

variables are tied to individual objects so if you destroy() part2 only part2 will be destroyed milo460 0 — 1y
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. greatneil80 2647 — 1y

1 answer

Log in to vote
Answered by 1 year ago
Edited 1 year ago

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.


Answer this question