What I’m trying to do is basically reassign an instance’s id or however it’s kept track of in the world so that all the variables that I already have for it are for the instance I replaced it with.
For example, I have a part in the workspace and it is indexed as local part = game.Workspace:WaitForChild(“Part”). I want to “reassign” the part’s instance number or whatever it is to an existing part named Part2 so that the part variable will then be referencing Part2 instead of Part.
The issue here is that I have no idea how roblox works beyond the lua so I don’t even know if this is possible at all much less possible with in-game scripts. Does anyone have any ideas?
Unless I am mistaken, all you have to do is assign part to the object you want the reference to be assigned to like this:
part = workspace.Part2
That is all. The original part will be completely de-referenced unless you create another variable for it.
However, make sure you do not use local before the variable part as this will create another reference, and your code will be confused on which part you will be referring to.
There is this variable _G and modules, however, I use modules rather than _G.
This is a thread from awhile back that has a better way of explaining it than I do at the moment. Currently in class. I know, shame on me.
They are still fine to use, but values are usually easily avoidable and can result in making more complex systems to work with. I usually only ever use them for something simple like leaderstats, permanent references/links or a server message, but nothing really complicated. I prefer to use objects, classes, and tables instead when applicable.