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

How Can I Make Object Go To Clicked Position? [SLOVED]

Asked by 9 years ago

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)

1 answer

Log in to vote
-1
Answered by
Tkdriverx 514 Moderation Voter
9 years ago

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.

0
Can you explain how this works? vincius0000 0 — 9y
0
Works. vincius0000 0 — 9y
0
Please explain your answer in the future. Perci1 4988 — 9y
Ad

Answer this question