Currently working with mob’s being controlled using Humanoid:MoveTo(), but unfortunately it’s only working while in studio mode. As soon as I play using Play Solo, .MoveToFinished is not fired and the mob’s are not removed. Here’s a few gif’s to show what I’m working with.
facts
-
Script is a function within a module script.
-
No local scripts are used.
Studio Test working as expected.
Play Solo not working correctly.
Whether some or none of the mobs disappear is inconsistent. However, as soon as one doesn’t despawn upon reaching its finished - none disappear from there.
Code
local function MoveHumanoid()
local target_reached = false
local connection
connection = EnemyHumanoid.MoveToFinished:Connect(function(reached) -- Not Firing.
target_reached = true
connection:Disconnect()
connection = nil
if target_reached then
print("Target reached") -- This is NOT printing.
if enemy then
enemy:Destroy()
end
local remainder = 0
if Core_Shield.Value > 0 then
if Core_Shield.Value - Damage.Value > 0 then
MainModule.DamageCoreShield(Damage.Value)
elseif Core_Shield.Value - Damage.Value <= 0 then
Core_Shield.Value = 0
end
end
if Core_Shield.Value - Damage.Value < 0 then
remainder = math.abs(Core_Shield.Value - Damage.Value)
end
if remainder > 0 and Core_Shield.Value <= 0 then
MainModule.DamageCoreHull(remainder)
end
elseif Core_Shield.Value <= 0 and Core_Health.Value > 0 then
MainModule.DamageCoreHull(Damage.Value)
end
end)
spawn(function()
while not target_reached do
wait()
local HumanoidState = EnemyHumanoid:GetState()
if HumanoidState == Enum.HumanoidStateType.None then -- an attempt to fix when they stopped moving.
MoveHumanoid()
end
if not EnemyHumanoid then
break
end
EnemyHumanoid:MoveTo(PhysCore.Position)
end
end)
end
MoveHumanoid()
If any more details are needed, feel free to ask.
Thanks for all contributions