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

How Do I Stop Cloned AI From Losing Joints?

I am cloning zombies from a template zombie (held in the Lighting) for a game I am building. When the zombies are cloned, then teleported, the zombie spawns dead and in pieces! This is the teleport and spawn portion of the script:

wait(math.random (1, (8 * RoundNum.Value)))
			local Zombie = game.Lighting.TemplateZombie:Clone()
			Zombie.Name = " "
			Zombie.Enemy.MaxHealth = 100 * RoundNum.Value
			Zombie.Enemy.Health = Zombie.Enemy.MaxHealth
			local choices = game.Workspace.spawnPads:GetChildren()
			local teleportto = (choices[math.random(1,#choices)])
				if teleportto~=nil then
					local torso = Zombie.Torso
					local location = teleportto.Position

					local x = location.x
					local y = location.y
					local z = location.z
				
					x = x
					z = z 
					y = y 

					local cf = torso.CFrame
					local lx = 0
					local ly = y
					local lz = 0
					torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
					Zombie.Parent = game.Workspace

Note that the "joints" are snaps. I checked and the zombies max health is at 100 (what is should be) Joints are labeld Neck, Left Hip, Left Shoulder, Right Hip, and Right Shoulder. When copied template zombie comes out of the spawn pad, it only has it's Neck left.

1 answer

✓ Accepted answer

I've had this problem before in the past, and the solution was to have an >:MakeJoints() after you place the model in a different parent space, like Workspace.

wait(math.random (1, (8 * RoundNum.Value)))
            local Zombie = game.Lighting.TemplateZombie:Clone()
            Zombie.Name = " "
            Zombie.Enemy.MaxHealth = 100 * RoundNum.Value
            Zombie.Enemy.Health = Zombie.Enemy.MaxHealth
            local choices = game.Workspace.spawnPads:GetChildren()
            local teleportto = (choices[math.random(1,#choices)])
                if teleportto~=nil then
                    local torso = Zombie.Torso
                    local location = teleportto.Position

                    local x = location.x
                    local y = location.y
                    local z = location.z

                    x = x
                    z = z 
                    y = y 

                    local cf = torso.CFrame
                    local lx = 0
                    local ly = y
                    local lz = 0
                    torso.CFrame = CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz))
                    Zombie.Parent = game.Workspace
		    Zombie:MakeJoints()

Hope this helps!

1 comment

0

Thanks! At first it didn't work, but I moved the Zombie.Parent = game.Workspace and Zombie:MakeJoints() before line 06 and it worked!

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