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

How to check a part's position relative to another part's position?

Asked by 8 years ago

I know how to change a part's position based on another part's position, but I can't figure out how to check if a part is, say, three units above another one. Can anyone point me in the right direction?

EDIT: Tried this, didn't work.

Error: Workspace.number.Script:3: attempt to call field 'Position' (a userdata value)

function checkmine()
    local mine = game.Workspace:FindFirstChild("mine")
    if mine.Position == script.Parent.Position + script.Parent.Position(4,0,0) then
        game.ReplicatedStorage:FindFirstChild("1"):Clone().Parent = script.Parent
    end
end

script.Parent.ClickDetector.MouseClick:connect(checkmine)
0
You mean like magnitude? User#9949 0 — 8y
0
Yes DrCylonide 158 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
function checkmine()
    local mine = game.Workspace:FindFirstChild("mine")
    if mine.Position == script.Parent.Position + Vector3.new(4,0,0) then
        game.ReplicatedStorage:FindFirstChild("1"):Clone().Parent = script.Parent
    end
end

script.Parent.ClickDetector.MouseClick:connect(checkmine)

try this?

0
Yep. I've done this before, I don't know why I didn't use Vector3 hah! DrCylonide 158 — 8y
0
I sometimes get simple brain farts like those too :) thehybrid576 294 — 8y
Ad

Answer this question