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

How to make detect when part has reached Destination?

Asked by
KenUSM 53
5 years ago

I realized that a Part in Roblox can not always be equivalent to it's Destination Part. So I was wondering if there was a way to Identify it part was near Destination Part or Detect has nearly stop moving because when I run the script below the Part does appear to stop moving to the naked eye but is always changing it's position slightly by very tiny digits. So can anyone help me with this problem I've encountered. Soldiers = Part Part2 = Destination, so you guys can know what I'm talking about.

while true do  
    wait()
    if Soldiers.Position.X ~= Part2.Position.X then 
        if Soldiers.Position.X > Part2.Position.X then 
            Soldiers.Position = Soldiers.Position - Vector3.new(0.02,0,0)
        end
        if Soldiers.Position.X < Part2.Position.X then 
            Soldiers.Position = Soldiers.Position + Vector3.new(0.02,0,0)
        end
    end
    if Soldiers.Position.Z ~= Part2.Position.Z then
        if Soldiers.Position.Z > Part2.Position.Z then 
            Soldiers.Position = Soldiers.Position - Vector3.new(0,0,0.02)
        end
        if Soldiers.Position.Z < Part2.Position.Z then 
            Soldiers.Position = Soldiers.Position + Vector3.new(0,0,0.02)
        end 
    end
    if Soldiers.Position.X == Part2.Position.X and Soldiers.Position.Z == Part2.Position.Z then -- this part of the script is almost never fired unless on the rare event that it actually meets it's destionation.
        print("oof") 
        break
    end
end

1 answer

Log in to vote
0
Answered by 5 years ago

you need to program several internal code that will detect several things at the same time,like for example setting the time and date of arriving at system D which is your internal script system!

Ad

Answer this question