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

Why is my clone duplicating twice?

Asked by cooldeath49 0 45 minutes ago Hi helpers, I know I'm really amateur and I suck at scripting, but I currently made a target for target practice that changes its color dependent on its health. However, once it dies, it respawns as normal, but after the second death, it duplicates and two targets appear instead. Help would be appreciated. The script is inside a humanoid root part, which is then inside a model, alongside a whole bunch of other body parts. (ignore the whole color and repeated chunk)

local Target = script.Parent.Parent

local backup = Target:Clone()

while true do

            local Hmd = Target.Humanoid.Health

    Torso.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

    Head.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

    RL.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

    LL.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

    RA.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

    LA.Color = Color3.new(1 - (Hmd * 0.01), Hmd * 0.01, 0)

 

    if Target.Humanoid.Health == 0 then

        wait(2)
    Target:Destroy()
    wait(0.5)
    Target = backup:Clone()
 
    Target.Parent = game.Workspace


end
    wait(0.1)
end

1 answer

✓ Accepted answer

It is in a while loop?

6 comments

0

yes

0

Also you state before the while loop to clone it.. then in the while loop you clone it again so..

0

Wait i think because you say Target = backup:Clone() but backup is already cloned

0

OHH i know its because the if Target.Humanoid.Health == 0 then is constantly running

0

ok

0

thx for your response, I used a lil bit of it.

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