I have an NPC that is supposed to move to certain spot before a script move the NPC again. I am using PathfindingService for the movement.
I am trying to use Magnitude to check if the NPC within a certain range of a Vector3 Value before being moved again.
This is the current script:
Summary
local Move
local Root = workspace.NPCs.Feugazi.HumanoidRootPart
local Humanoid = Root.Parent.Humanoid
local Move1 = workspace.Move1
local Magnitude = (Root.Position-Move1.Position).Magnitude
print("Manitude should print")
print(Magnitude)
-- CHECKS NPC LOCATION
if Magnitude ~= 2 then
print("Waiting for less than 2 magnitude")
repeat wait() until Magnitude < 1.5
print("Magnitude Worked")
print(Root.Position)
Move = require(script:WaitForChild("Move1"))
end
The script is working up until repeat wait() until Magnitude < 1.5 , and is not executing the two prints after that.
Is there a better way for me to check if the magnitude is within a certain range? Am I not noticing an error within my script?
EDIT:
I used the Command Bar to check the Magnitude while testing, and it is within the 1.5 range that I have set, but the script is still not moving past repeat wait()
You are only setting magnitude 1 time as stated above to fix this you need to get it each time the repeat loop runs through to check the new magnitude of the 2 parts here is where it should be in the below script:
local Move
local Root = workspace.NPCs.Feugazi.HumanoidRootPart
local Humanoid = Root.Parent.Humanoid
local Move1 = workspace.Move1
local Magnitude = (Root.Position-Move1.Position).Magnitude
print("Manitude should print")
print(Magnitude)
-- CHECKS NPC LOCATION
if Magnitude ~= 2 then
print("Waiting for less than 2 magnitude")
repeat wait()
Magnitude = (Root.Position-Move1.Position).Magnitude
until Magnitude < 1.5
print("Magnitude Worked")
print(Root.Position)
Move = require(script:WaitForChild("Move1"))
end