:Clone() wont work?

I am making a NPC monster that gets bigger as damage is done, but that part is already done,

I am trying to get it to Clone after its at its final damage stage

I did script.Parent:Clone()

but it wont work, or show any errors, what is going on here?

> function Hit(hit)
> 	local human = hit.Parent:FindFirstChild("Humanoid")
> 	if human ~= nil then
> 		if hitfree then
> 			hitfree = false
> 			human.Health =  human.Health - (3 * _G.firesize)
> 			script.Parent.Zombie.WalkSpeed = 2.5 * _G.firesize
> 			script.Parent.Torso.Sound.Volume = .25 * _G.firesize
> 			script.Parent.Torso.Fire.Heat = 1.25 * _G.firesize + 5
> 			if _G.firesize < 16 then
> 				script.Parent.Torso.Fire.Size = _G.firesize + 1
> 				_G.firesize = script.Parent.Torso.Fire.Size
> 				if _G.firesize > 10 then
> 					script.Parent:Clone()
> 					script.Parent.Torso.Transparency = .5
> 					script.Parent.Head.Transparency = .5
> 					script.Parent["Left Arm"].Transparency = .5
> 					script.Parent["Left Leg"].Transparency = .5
> 					script.Parent["Right Arm"].Transparency = .5
> 					script.Parent["Right Leg"].Transparency = .5
> 				end
> 				wait(1)
> 			end
> 			_G.fourfiveseventimer = 10
> 			hitfree = true
> 		end
> 	end
> end
3 Likes

Solution?


Did you forget to parent the clone? :thinking:

Warning!
Beware of recursions, you don’t want this to be cloned and placed and cloned again:
ScriptA is parent of A, A is cloned, creating B and thus creating ScriptB.
…but then ScriptB creates C and ScriptC! OH NO!

Oh, and it turns out it is a function. Should be fine, but it seems like a self-replicating script.

Create a deep copy of a Roblox Instance and all of its descendants
Source: Instance | Documentation - Roblox Creator Hub

2 Likes

Try parenting your cloned item. There are 2 ways you could do this:

  1. script.Parent:Clone().Parent = game.Workspace

  2. local clone = script.Parent:Clone()
    clone.Parent = game.Workspace
    

Both get the job done, but the 2nd option is better for if you are going to do other things with the cloned object.

7 Likes
local CloneVariable = script.Parent:Clone()
CloneVariable.Torso.Transparency = .5
CloneVariable.Head.Transparency = .5
CloneVariable["Left Arm"].Transparency = .5					
CloneVariable["Left Leg"].Transparency = .5
CloneVariable["Right Arm"].Transparency = .5					
CloneVariable["Right Leg"].Transparency = .5
CloneVaribale.Parent = workspace

try this

2 Likes

Is the property on whatever you’re cloning “.Archivable” set to true?

This essentially tells Roblox if the instance can be copied or not :slight_smile:

You also should make sure you set the .Parent of the clone, as originally any copied script won’t run because it’s parent will be nil.

2 Likes

I used
script.Parent:Clone().Parent = game.Workspace

But when it clones if just clones directly inside the other NPC
how could I go about making it spawn outside of the NPC

You have to position the cloned model. One way you could do this is by finding the position of the PrimaryPart and using :MoveTo() to move the clone left/right/forward/backward. Example:

local clone = script.Parent:Clone()
clone.Parent = game.Workspace
local PrimaryPosition = clone.PrimaryPart.Position
clone:MoveTo(Vector3.new(PrimaryPosition.X + 10, PrimaryPosition.Y, PrimaryPosition.Z + 10))

This will move your clone by 10 units on the X and Z axis, while keeping the Y position the same.

2 Likes