Destroy Script Not Running

Hey, I have a piece of script that should be detecting deleting a cloned model after a number value falls below 0. The script isn’t really running and the script above is just taking a cloned hitbox part and setting the cloned model’s CFrame to follow it. Any ideas on how I can fix this? (This is for a tower defense game) (No script errors either)

1 Like

Entity2.CAllyHealth.Changed:Connect()

Just tried that and still doesn’t work, I think the problem is with the function not running in general, the variables should all be set up correctly.

oh wait

local AllyFolder = workspace.Battle:WaitForChild("Allies")
local TweenService = game:getService("TweenService")

AllyFolder.ChildAdded:Connect(function(ent)

local Model = game.ReplicatedStorage.Humans.AllySkin:FindFirstChild(ent.Name) -- idk
Model:Parent = workspace.Battle.AllySkin

ent.CAllyHealth.Changed:Connect(function()
local entHp = ent.CAllyHealth.Value;
if tonumber(entHp) <= 0 then
Model:Destroy()
print("entity2 has been Destroyed!")
end
end)

while wait() do
Model:SetPrimaryPartCFrame(ent.CFrame)
end
end)

idk if its works lol

1 Like

This error pops up, but I don’t really see why:


image

Figured it out, needed a waitforchild. Thanks for the help.