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

[Not Answered]Why is this script not respecting the min range?

Asked by 10 years ago
torso = script.Parent.Torso
maxrange = 70
minrange = 20
target = nil
tor = nil

function findNearestTarget()
    plrs = game.Players:GetChildren()
    for i, plr in ipairs(plrs) do
        if plr.Character ~= nil then
            if plr.Character:findFirstChild("Humanoid") and plr.Character.Humanoid.Health>0 then
                tor = plr.Character.Torso
                if target == nil then
                    if ((torso.Position - tor.Position).magnitude <= maxrange) and ((torso.Position - tor.Position).magnitude >= minrange)  then
                        target = plr.Character
                    end
                end
            end
        end
    end
end

while true do
    wait(.1)
    findNearestTarget()
    if target ~= nil then
        script.Parent.Zombie.WalkToPoint = Vector3.new(tor.Position.X,0,tor.Position.Z)
        script.Parent.Torso.BodyPosition.position = Vector3.new(0,tor.Position.Y,0)
    end
end

So what im trying to do is a Zephir styled enemie (from the minecraft mod aether) that flies around and if you get to close to him, he starts following you. So i have seted the maxrange and the minrange, if the monster is less then 70 studs away to the caracter, he will follow you. But if hes 20 studs away from you, he will stop. Well this is working perfectly, but the mob keeps following you even if hes less then 20 studs away from you. Can someone please fix this?

1 answer

Log in to vote
0
Answered by 10 years ago

bumpity bump

Ad

Answer this question