You are creating the colored clones from workspace[‘Evolution Tree’], and you parent the first branching species (that link to the RootSpecie) to workspace[‘Evolution Tree’], which leads to the colored clones keeping that link to the RootSpecie. Try this script instead:
local RootSpecie = workspace.RootSpecie
local SpecieNumber = 0
local Year = 50
local Yearmini = 10
for i = 1,4 do
local Specie = RootSpecie:Clone()
local attachment1 = Instance.new("Attachment",Specie)
attachment1.Name = 'RootAttachment1'
local Attachment2 = Instance.new("Attachment",RootSpecie)
Attachment2.Name = 'RootAttachment2'
local beam = Instance.new("Beam",Specie)
beam.Name = 'RootBeam'
-- getting ready
Specie.BrickColor = BrickColor.random()
Specie.Parent = workspace["Evolution Tree"]
Specie.Position = Specie.Position + Vector3.new(
math.random(-30, 30),
math.random(Yearmini, Year),
math.random(Yearmini, Year)
)
Specie.ParentSpecie.Value = RootSpecie.Name
beam.FaceCamera = true
beam.Attachment0 = attachment1
beam.Attachment1 = Attachment2
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0,Specie.Color),
ColorSequenceKeypoint.new(1,RootSpecie.Color)
})
end
for _, SpecieI in pairs(workspace["Evolution Tree"]:GetChildren()) do
for i = 1,10 do
local Specie = SpecieI:Clone()
local rootBeamInstances = {'RootBeam','RootAttachment1','RootAttachment2'}
for _, child in Specie:GetChildren() do
if table.find(rootBeamInstances,child.Name) then
child:Destroy()
end
end
local attachment1 = Instance.new("Attachment",Specie)
local Attachment2 = Instance.new("Attachment",SpecieI)
local beam = Instance.new("Beam",Specie)
-- getting ready
Specie.BrickColor = BrickColor.random()
Specie.Parent = workspace["Evolution Tree"]
Specie.Position = Specie.Position + Vector3.new(
math.random(-30, 30),
math.random(Yearmini, Year),
math.random(Yearmini, Year)
)
Specie.ParentSpecie.Value = SpecieI.Name
beam.FaceCamera = true
beam.Attachment0 = attachment1
beam.Attachment1 = Attachment2
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0,Specie.Color),
ColorSequenceKeypoint.new(1,SpecieI.Color)
})
end
end
Your welcome. Also, I had a small mistake in the code I sent above, as you don’t actually need to check for ‘‘RootAttachment2’’ in the cloned Specie children, as that isn’t cloned along the Specie (since it is parented to RootSpecie)
when i tried repeat 20 time, there is same bugs. Can you fix it?
lua
for i = 1,20 do
for _, SpecieI in pairs(workspace["Evolution Tree"]:GetChildren()) do
for i = 1,20 do
if SpecieI["Died?"].Value ~= true then
local Specie = SpecieI:Clone()
local rootBeamInstances = {'RootBeam','RootAttachment1','RootAttachment2'}
for _, child in Specie:GetChildren() do
if table.find(rootBeamInstances,child.Name) then
child:Destroy()
end
end
local attachment1 = Instance.new("Attachment",Specie)
local Attachment2 = Instance.new("Attachment",SpecieI)
local beam = Instance.new("Beam",Specie)
-- getting ready
SpecieNumber += 1
Specie.Name = "Specie_"..SpecieNumber
Specie.BrickColor = BrickColor.random()
Specie.Parent = workspace["Evolution Tree"]
Specie.Position = Specie.Position + Vector3.new(
math.random(-30, 30),
math.random(Yearmini, Year),
math.random(-30, 30)
)
Specie.ParentSpecie.Value = SpecieI.Name
beam.FaceCamera = true
beam.Attachment0 = attachment1
beam.Attachment1 = Attachment2
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0,Specie.Color),
ColorSequenceKeypoint.new(1,SpecieI.Color)
})
if math.random(1,30) == 1 then
Specie["Died?"].Value = true
end
end
end
end
end
for i = 1,20 do
for _, SpecieI in pairs(workspace["Evolution Tree"]:GetChildren()) do
for i = 1,20 do
if SpecieI["Died?"].Value ~= true then
local Specie = SpecieI:Clone()
for _, child in Specie:GetChildren() do
if child:IsA('Attachment') or child:IsA('Beam') then
child:Destroy()
end
end
local attachment1 = Instance.new("Attachment",Specie)
local Attachment2 = Instance.new("Attachment",SpecieI)
local beam = Instance.new("Beam",Specie)
-- getting ready
SpecieNumber += 1
Specie.Name = "Specie_"..SpecieNumber
Specie.BrickColor = BrickColor.random()
Specie.Parent = workspace["Evolution Tree"]
Specie.Position = Specie.Position + Vector3.new(
math.random(-30, 30),
math.random(Yearmini, Year),
math.random(-30, 30)
)
Specie.ParentSpecie.Value = SpecieI.Name
beam.FaceCamera = true
beam.Attachment0 = attachment1
beam.Attachment1 = Attachment2
beam.Color = ColorSequence.new({
ColorSequenceKeypoint.new(0,Specie.Color),
ColorSequenceKeypoint.new(1,SpecieI.Color)
})
if math.random(1,30) == 1 then
Specie["Died?"].Value = true
end
end
end
end
end