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

Does changing variable change children?

Ok, so I have an interesting question.

So I have a rocketship I built that is supposed to clone and launch from the land. Problem is, I pre-declared the rocket and children variables as such:

local Rocket = game.ServerStorage.FullRocket
local Booster1 = Rocket.Rocket.Tanks.Booster --Booster 1 during seperation stage
local Booster2 = Rocket.Rocket.Tanks.Booster2 --Same as booster 1
local Tank = Rocket.Rocket:FindFirstChild("Fuel Tank") --Fuel tank for seperation
local ShuttleMain = Rocket.Shuttle["Cargo Bay"].Main --The main part which controls the rocket
local Effects = Rocket.Effects --The rockets effects, such as the fire and smoke

Question is, can I change the rocket variable and STILL be able to use the children without redefining? Like this:

local Rocket = game.ServerStorage.FullRocket
local Booster1 = Rocket.Rocket.Tanks.Booster --Booster 1 during seperation stage
local Booster2 = Rocket.Rocket.Tanks.Booster2 --Same as booster 1
local Tank = Rocket.Rocket:FindFirstChild("Fuel Tank") --Fuel tank for seperation
local ShuttleMain = Rocket.Shuttle["Cargo Bay"].Main --The main part which controls the rocket
local Effects = Rocket.Effects --The rockets effects, such as the fire and smoke

wait(1)
local Clone = Rocket:Clone()
Clone.Parent = workspace
Rocket = Clone --Change rocket var to clone
Booster1.Activated = false --Could I do this, for example

Thank you for any help!

1 comment

0

I don't believe so, I think you would have to using something like "Clone.Rocket.Tanks.Booster1.Activated"

2 answers

✓ Accepted answer

no you can't, and here is why:

first start by looking at my answer on this post;

now with that out the way, when you do Instance:Clone(), it creates a new object, which means you now have 2 objects.. therefore, the variables still point to their original object and you need to manually change the reference of the variables..

even if you were to destroy their first reference, they still point to it: thats why it's common to set a variable to nil after you destroy the object it holds reference to.. and this is very important because - if you don't - it holds reference to the object you no long need, which will cause memory leak, and this is especially critical when the objects are in an array(table)..

also go check out my answer on this post, it has a great example of how the roblox hierarchy system works, and hopefully an insight on why variables don't change automatically

1 comment

0

Thank you :D

Yes you can I don't really know what else to say except for to keep track of what you changed.

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