Im trying to clone 3 enemies and have them attack you, ive gotten pretty far and been able to clone them, teleport them to a specific location, rotate them and the player can kill them. how the script that clones the enemies works is:
-
it clones the enemies from one enemy that sits outside the map with all the scripts and stuff to make the enemy work
-
it teleports the cloned enemies to specific locations and rotates them
The problem is that when i kill one of the enemies, the next cloned enemies instantly die or just dissapear. When i kill an enemy i remove their humanoid to hide its name and health, i dont think removing the dead enemies humanoid is causing the problem but i thought id mention it.
I want to stop the cloned enemies from dying as soon as they spawn
I have tried a few things, but they all have the same problem that the cloned enemies die, ive tried googling a solution but couldnt find anything, ive tried to use chatgpt to figure out how to solve it but that didnt work. Ive also thought about having like 30 enemies outside the map and teleporting a few in but that would probably make the game very laggy.
I have basically never scripted, but im trying to learn it by making a simple game.
here are the scripts:
script that clones the enemies and teleports them
local modeltoclone = game.Workspace.CloningEnemy --enemy outside map
local newclone1 = modeltoclone:Clone() --first clone
local newclone2 = modeltoclone:Clone() --second clone
local newclone3 = modeltoclone:Clone() --third clone
-- there is some stuff in between here but i removed it since it isnt important
newclone1.Name = "Bee" --changes name
newclone1:SetPrimaryPartCFrame(CFrame.new(-20.383, 2.376, 211.419)) --teleports cloned enemy
rotation = CFrame.Angles(0, math.rad(25), 0) --this line and the 2 under it rotate the cloned enemy
ModelCF = newclone1.PrimaryPart.CFrame
newclone1:SetPrimaryPartCFrame(ModelCF * rotation)
wait() --under this, the same thing is done for 2 more cloned enemies, copy paste of the code above, just position and rotation changed
enemy death script
while true do
wait(0.1)
if script.Parent.Humanoid.Health<1 then
script.Parent.Head.Damage.Enabled = false --disables script that deals damage
idle:Stop()
local chance = math.random(1,3) --picks random number to choose what parts to disconnect from body (this is unnecessary but id like to keep it if possible)
if chance == 1 then
script.Parent.HumanoidRootPart["Left Wing"]:Destroy()
script.Parent.HumanoidRootPart.Head:Destroy()
script.Parent.Humanoid:Destroy() --this could maybe be causing it?
wait(20)
script.Parent.Tail:Destroy() -- this line and the 3 under it just destroy some parts, leaving just the head and a wing together with a few scripts
script.Parent["Right Wing"]:Destroy()
script.Parent["Rear Body"]:Destroy()
script.Parent["Front Body"]:Destroy()
wait(40)
script.Parent:Destroy() --this destroys the entire model
end
if chance == 2 then
--copy paste of the code above, but first 2 lines are changed to be other parts
end
if chance == 3 then
--copy paste of the code above, but first 2 lines are changed to be other parts
end
end
end
i might have forgotten to add something, i havent posted anything on here in a while.