Hello!
So I made a system that loops trough every mob, and respawns them when they die.
However, when the dummy respawns (for the second time), he dupes and floats in the air.
Does anyone know how to fix this? (Codes below the video)
For info, ‘OriginalPosition’ is a Vector3 that represents their original respawn spot (that works btw)
local function Respawn(Parent, Clone, Mob, OriginalPosition)
if not MobConfigs:FindFirstChild(Clone.Name) then return end
task.wait(MobConfigs:WaitForChild(Clone.Name):WaitForChild("RespawnDelay").Value)
Mob:Destroy()
Clone.Parent = Parent
Clone:MakeJoints()
Clone:MoveTo(OriginalPosition)
SetupMob(Clone)
for i, v in pairs(Clone:GetChildren()) do if v:IsA("BasePart") then v.Anchored = false end end
Clone:WaitForChild("Humanoid").Died:Connect(function()
local Target = FindTarget(Clone)
Respawn(Parent, Clone:Clone(), Clone, OriginalPosition)
end)
end
-->>------------------------------------------------------------------------------<<--
--<< LOOP TROUGH ALL MOBS >>--
for i, MobFolder in pairs(script.Parent:GetChildren()) do
if MobFolder:IsA("Folder") then
for i, Mob in pairs(MobFolder:GetChildren()) do
if Mob:IsA("Model") then
if Mob:FindFirstChildWhichIsA("Humanoid") then
local MobConfig = MobConfigs:WaitForChild(Mob.Name)
local Parent = Mob.Parent
local Humanoid = Mob:WaitForChild("Humanoid")
local WalkLimit = Mob:WaitForChild("WalkLimit")
local Clone = Mob:Clone()
local OriginalPosition = WalkLimit:WaitForChild("Center").Position
-->>------------------------------------------------------------------------------<<--
--<< RESPAWN >>--
local WalkLimit = Mob:WaitForChild("WalkLimit")
for i, v in pairs(WalkLimit:GetChildren()) do if v:IsA("BasePart") and v ~= WalkLimit.PrimaryPart then v.Touched:Connect(function(Hit) if Hit and (Hit.Parent == Mob or Hit.Parent == Clone) then Respawn(Parent, Clone, Mob, OriginalPosition) end end) end end
Humanoid.HealthChanged:Connect(function() if Humanoid.Health == 0 then Respawn(Parent, Clone, Mob, OriginalPosition) end end)
end
end
end
end
end
Ty for any help!