Mouse.hit.position making the object go INSIDE the part

		function GetMousePoint(X, Y)
			--local RayMag1 = Camera:ScreenPointToRay(X, Y) --Hence the var name, the magnitude of this is 1.
			--local NewRay = Ray.new(RayMag1.Origin, RayMag1.Direction * 1000)
			--local Target, Position = workspace:FindPartOnRay(NewRay, Player.Character)
				--return Position
				return Mouse.Hit.Position
		end
		
			local PlaceAsset = RoadPack:FindFirstChild(PickedValue.Value):Clone()
			PlaceAsset.Parent = workspace
			if PlaceAsset:IsA("Model") then
				print(GetMousePoint(Mouse.X, Mouse.Y))
				PlaceAsset:SetPrimaryPartCFrame(CFrame.new(GetMousePoint(Mouse.X, Mouse.Y) ) *CFrame.Angles(math.rad(PlaceAsset.PrimaryPart.Orientation.X),math.rad(PlaceAsset.PrimaryPart.Orientation.Y), math.rad(PlaceAsset.PrimaryPart.Orientation.Z))) 
			else
				
				PlaceAsset.Position = GetMousePoint(Mouse.X, Mouse.Y)
			end

https://gyazo.com/6d7253a68175029355f130bcbccd998b

This is my script which takes a model (or a part) and duplicates it to the mouse position where clicked.

The issue: Mouse.Hit.P Is returning a position thats INSIDE the part, as you can see in the video, the model is spawning with only the top of the model sticking out, the rest is below inside the part.

How would I fix it to move it up enough to make sure the bottom is on top of the part?

It works sort of but it still doesnt bring it high enough, (a bit of the bottom was still going thru the part)

Id never know how much I need to tweak it because the part may be a different size each time.

If I am correct, you could use Mouse.TargetFilter. It worked with the plane I was creating, however I haven’t done much research upon this function so the case your trying to fix might not work with it.

Wouldnt that just ignore the part ( the ground part ) entirely and make the model spawn way below? I still want it to see the part, i just dont want it to spawn in it, i want it to spawn on top

Yeah I figured as much
Im also horrible with math so Im not sure how to go about this either…

1 Like