model = script.Parent.Parent:Clone() function tower(part) if part.Parent:findFirstChild("Humanoid") and game.Players:playerFromCharacter(part.Parent) then local old = script.Parent.Parent local oldParent = old.Parent old:Remove() wait(4) local new = model:Clone() new.Parent = oldParent old:Destroy() end end script.Parent.Touched:connect(tower)
For some reason, when i regen the model described in there, all the parts are disconnected from each other (Meaning that, instead of requiring explosions to be destroyed, it gets destroyed by it's own) What to?
Well, first off, playerFromCharacter()
is deprecated. Use GetPlayerFromCharacter
instead.
Second, you're doing old:Remove()
(which is also deprecated, use Destroy() instead.) and then old:Destroy()
. If you removed it, why would you bother destroying it?
Anyways, to fix your main problem, you must use the MakeJoints()
method. Here, I cleaned up your code and added MakeJoints()
.
local model = script.Parent.Parent --Local variables are more efficient! local copy = model:Clone() function tower(part) if game.Players:GetPlayerFromCharacter(part.Parent) then --No need to check for a humanoid, as long as it's a player it will have one. local new = copy:Clone() local parent = model.Parent model:Destroy() wait(4) new.Parent = parent new:MakeJoints() end end script.Parent.Touched:connect(tower)
I hope i helped!