Hello! I need your help. When I click on board my part that script creates spawns on top of that board. I need your help to make it spawn where you click it not on top. Here is everything that is in the script.
script.Parent.Equipped:connect(function(mouse) mouse.Button1Down:connect(function() if mouse.Target.Name == "DrawBoard" then local instspr = Instance.new("Part") instspr.Parent = mouse.Target instspr.Position = mouse.hit.p instspr.Anchored = true instspr.CanCollide = false instspr.BrickColor = BrickColor.new("Institutional white") instspr.Name = "DrawPix" instspr.FormFactor = Enum.FormFactor.Custom instspr.Size = Vector3.new(0.2, 0.2, 0.2) instspr.BottomSurface = Enum.SurfaceType.Smooth instspr.TopSurface = Enum.SurfaceType.Smooth end end) end)
Try instspr.CFrame = CFrame.new(mouse.Hit.p) * CFrame.new(0, 0.1, 0)
instead of instspr.Position = mouse.Hit.p
This works best because Position
doesn't place parts INSIDE other parts. If a Position given intersects another part, it will move the part to the highest point matching the same x and z coordinates. So, it will spawn the part at the top of the intersected part. The reason you use CFrame here is so it will spawn the part right where you click, INSIDE the part you clicked on. The * CFrame.new(0, 0.1, 0)
is to make sure it sticks out of the part, so it's still visible. Basically changing the CFrame value by 0.1 studs on the y axis.