Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

2 comments

0

You mean like magnitude?

0

Yes

1 answer

✓ Accepted answer
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?

2 comments

0

Yep. I've done this before, I don't know why I didn't use Vector3 hah!

0

I sometimes get simple brain farts like those too :)

This discussion is preserved as it was. New answers, comments, and votes are closed.