Basically this happens after I clone the object ( its like when in a tower defense game, you have to upgrade towers. And this occurs after upgrading the tower once, it works before upgrading )
function findClosestEnemy(fromTower)
for i, v in pairs(game.Workspace.Enemies:GetChildren()) do
local distance = (v.HumanoidRootPart.Position - fromTower.HumanoidRootPart.Position).Magnitude
if distance < 15 then
--print("Shoot")
return v
end
end
end
it errors here, even though this same function works before cloning ( upgrading the tower ).
Wait I found out the problem, when I cloned it, I only set the torso’s position and body parts, I didn’t set the humanoidRootPart’s position. Maybe thats why it bugs.
Now it works fine ( since I heard you have to set the torso’s position if you are dealing with r6 characters )