I was on studio experimenting with this script, I kept on receiving the same output. The problem is that it only prints not found. I want it to print found can anyone help? Also can anyone explain why line 6 doesn't work.

local Part = workspace.Part -- Change this if needed
local Part2

local Target = Part.Position + Vector3.new(0,10,0)
for i,v in pairs(workspace.Model:GetChildren()) do -- Change the model name
    if v.Position == Target then
        Part2 = v
        print("Found! Yay")
    else
        print("Not Found")
    end
end

##Fixed answer: I forgot to incorporate 2 parts and make 1 of the parts a model. I then made the model 10 studs above the part in the workspace, so for e.g. let's say the part's position was 1.5, 1.5 + 10 = 11.5.

Asset for this is here

5 comments

1

Target is already a Vector3.

0

^

0

anyone

0

directly compare Target to v.Position instead of enclosing it in a Vector3.new constructor

0

A slight mistake will cause the whole if statement to mess up your code. Magnitude checks for the distance and it's much better.