Finding The Closest Point To A Part

The goal is pretty simple, Find a parts closest point to another part (They Would Be Touching) OR another way to stick a ball to any type of object thats tagged

Im using a vector force to apply force to the wall therefore Stoping it from falling and keeping it stuck too the wall

Here is my code (In this segment but it should be enough):

cs:GetInstanceAddedSignal("Sticky"):Connect(function(Plr)
	if Plr:IsA("Player") then
		
	local Attachment = Instance.new("Attachment")
	Attachment.Parent = Plr.Character.HumanoidRootPart
	Attachment.Name = "Attachment"
	
	local Force = Instance.new("VectorForce")
	Force.Parent = Plr.Character.HumanoidRootPart
	Force.Name = "Force"
	Force.Attachment0 = Attachment
	Force.Force = Vector3.new(0,0,0)
	
	local LastTouchedObject = nil
	
	Plr.Character.HumanoidRootPart.Touched:Connect(function(T)		
		if T:HasTag("Stickable") then
			LastTouchedObject = T
				print()
		end
	end)
	
	Plr.Character.HumanoidRootPart.TouchEnded:Connect(function(T)
		if T:HasTag("Stickable") then
			LastTouchedObject = nil
		end
	end)
	
	
	repeat
		task.wait(0.1)
		if LastTouchedObject then
		Force.Force = Vector3.new(500, 500, 500) * LastTouchedObject.CFrame.LookVector
		print(Force.Force)
		else
			Force.Force = Vector3.new(0,0,0)
		end
	until false
	
	end
end)

Any help is appreciated

I assume you mean the shortest distance from any (x,y,z) on partA to any (x2,y2,z2) on partB?

It doesn’t seem very documented, but have you checked :GetClosestPointOnSurface?

Not sure what you mean by that but i need a position thats the closesed point to the wall

Ill check this out when i get home

Could you please be more clear?

Found a solution thank you though

1 Like