I made a script trying to regen models and its not working BUT this keeps happening a LOT during scripting can someone please tell me why before i lose my sanity? what it does every minute it is supposed to clone it into Replicated Storage then it Destroys the existing one and then it waits for the child of Replicated Storage of the testhouse now i know i maybe done a lot wrong since i am still pretty new to scripting here is the script:
local REGEN = game.Workspace.TestHouse local MODEL_BACKUP = REGEN:Clone() local work = game.Workspace while true do wait(60) MODEL_BACKUP = game.ReplicatedStorage REGEN:Destroy() game.ReplicatedStorage:WaitForChild(REGEN) = work end
Nothing wrong with being new to scripting, we were all there.
In order to shift where the cloned object is, you have to change the parent property of the object. So instead of doing "MODEL_BACKUP = game.ReplicatedStorage" you would type "MODEL_BACKUP.Parent = game.ReplicatedStorage"
The second thing is on line 9, you say "WaitForChild(REGEN)" which will not work for several reasons.
*REGEN was destroyed and has it's parent value locked to nil *WaitForChild take a string, and you're passing in an object
If you wanted to wait for the new TestHouse, you would just do "game.ReplicatedStorage:WaitForChild("TestHouse")" or you could even do "game.ReplicatedStorage:WaitForChild(MODEL_BACKUP.Name)"
The second one uses the name of MODEL_BACKUP as it should be the same as REGEN.Name which will be "TestHouse".
Lastly we need to talk about how you're setting the variables and how since this is a loop will eventually fail. How your code is written, after we changed everything to conform to Lua, will still have a logical problem. Every minute, it makes MODEL_BACKUP which is the original clone of REGEN and we set it's parent to ReplicatedStorage. Then we destroy REGEN, but on the second go destroying the REGEN variable doesn't make sense, we already did it once.
We can fix these logical errors by thinking back to what you wanted to do in the first place: Clone an object, move the clone to ReplicatedStorage. Destroy the original object in workspace, and move the clone into workspace.
In this case, I can rewrite most of the logic fairly easily.
This whole thing could be rewritten as:
local REGEN = game.Workspace.TestHouse local MODEL_BACKUP = REGEN:Clone() local work = game.Workspace while true do wait(60) --//When you clone an object, it sets it's parent to nil, so we don't really need to move it anywhere unless you need it in ReplicatedStorage for a reason. --//we destroy the original object, and parent the clone to workspace REGEN:Destroy() MODEL_BACKUP.Parent = work --//Next we reassign REGEN as MODEL_BACKUP and repeat what we did at the top of the screen. This will ensure that when the loop comes around again everything work as expected. REGEN = MODEL_BACKUP MODEL_BACKUP = REGEN:Clone() end
If you have any other questions feel free to message me.
I see what the problem is, (I believe). I think you're not defining the parent of the model you're trying to spawn. This should help!
local REGEN = game.Workspace.TestHouse local MODEL_BACKUP = REGEN:Clone() local work = game.Workspace while true do wait(60) MODEL_BACKUP.Parent = game.ReplicatedStorage REGEN:Destroy() game.ReplicatedStorage:WaitForChild("MODEL_BACKUP").Parent = game.Workspace end
I'm still a little confused on what you're trying to do, but if this works let me know.