Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I used the magnitude but why does it only worked on the later paths but not on the first few paths?

Asked by 1 year ago

Line 6 Help would be so much appreciated

function jeeptarget()
    for _, v in pairs(Zombies) do
        if v:FindFirstChild("HumanoidRootPart") then
            if v.HumanoidRootPart:FindFirstChild("Node") then
                if Model.PrimaryPart then
                    if (Model.PrimaryPart.Position - v.HumanoidRootPart.Node.WorldPosition).magnitude < _Range.Value then
                        if v:FindFirstChild("Humanoid") then
                            if Humanoid then
                                local ZombieHP = v.Humanoid.Health
                                local TowerHP = Humanoid.Health
                                v["Humanoid"].Health = v["Humanoid"].Health - TowerHP
                                Humanoid.Health = Humanoid.Health - ZombieHP
                            end
                        end
                    end
                end
            end
        end
    end
end

function onUpdate()
    if Model.PrimaryPart then
        if _MaximumPath.Value <= _CurrentPath.Value  then
            jeeptarget()
            if Model.PrimaryPart then
                if (Model.PrimaryPart:WaitForChild("Node").WorldPosition - ReversedPath:WaitForChild(_CurrentPath.Value).Position).magnitude < 0.5 then
                    _CurrentPath.Value = _CurrentPath.Value - 1
                else
                    Model.PrimaryPart:WaitForChild("AlignPosition").Attachment1 = ReversedPath:WaitForChild(_CurrentPath.Value):WaitForChild("Node")
                    Model.PrimaryPart:WaitForChild("AlignPosition").MaxVelocity = _Speed.Value
                    Model.PrimaryPart:WaitForChild("AlignOrientation").Attachment1 = ReversedPath:WaitForChild(_CurrentPath.Value):WaitForChild("Node")
                end
            end
        else
            Humanoid:TakeDamage(Humanoid.Health)
        end
    end
end

Answer this question