Mouse.Target.Position?

  1. What do you want to achieve? Keep it simple and clear!
    Part position go to mouse position on baseplate.

  2. What is the issue? Include screenshots / videos if possible!
    how to fix that?

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Mouse.Move:Connect(function()
	if Mouse.Target ~= nil and Mouse.Target ~= workspace.Baseplate then
		
		Mouse.Button1Down:Connect(function()
			workspace.SelectionBox.Color3 = Color3.new(0.666667, 0, 0)
			workspace.SelectionBox.SurfaceColor3 = Color3.new(0.666667, 0, 0)
			
			Mouse.Target.Position = Mouse.Hit.Position --that
		end)
		
		workspace.SelectionBox.Adornee = Mouse.Target
		Mouse.Icon = "rbxasset://SystemCursors/PointingHand"
	else
		workspace.SelectionBox.Adornee = nil
	end
end)

or that:

Mouse.Move:Connect(function()
	if Mouse.Target ~= nil and Mouse.Target ~= workspace.Baseplate then
		
		workspace.Part.Position = Mouse.Hit.Position
		
		workspace.SelectionBox.Adornee = Mouse.Target
		Mouse.Icon = "rbxasset://SystemCursors/PointingHand"
	else
		workspace.SelectionBox.Adornee = nil
	end
end)

What is the error or what tou try to do? Is there an error?

I want the block to move through baseplate and not through the air.

Ah, you can do a simple formula, replace the Y Axis (or the Axis which suits best) from the vector with the position and size of the Baseplate plus the “radius” of the part; the Axis Y (or the Axis wich suits best) / 2.

Basically don’t use the complete vector, instead “attach” an Axis to your preference.

If you don’t understand this I could think more.

I’d like to know more about how to do that, if you can. Thank you.

Sure :smiley: (notice that I’m from my cellphone).

So first we got the position and you set the workspace.Part.Position:

    workspace.Part.Position = Mouse.Hit.Position

Instead of setting the position directly to the mouse position; “attach” some Axis wich suits best for (in this case the Y Axis from the Vector3), to the Baseplate.

How we do this?:

local basePlate = workspace.Baseplate
local size, position = basePlate.Size, basePlate.Position

local radius = workspace.Part.Size.Y/2
local positionY = position.Y + (size.Y/2) + radius

Mouse.Move:Connect(function()
	if Mouse.Target ~= nil and Mouse.Target ~= workspace.Baseplate then
		local cf = Mouse.Hit
		local position = cf.Position
		workspace.Part.Position = Vector3.new(position.X, positionY, position.Z)
		
		workspace.SelectionBox.Adornee = Mouse.Target
		Mouse.Icon = "rbxasset://SystemCursors/PointingHand"
	else
		workspace.SelectionBox.Adornee = nil
	end
end)
2 Likes

I hope this help you more (and this written code function), if you continue having trouble don’t have fear and tell me.

1 Like

No way. With a mobile phone try so hard, thank you for that!

1 Like

Was nothing!
Could you close it with giving the solution?
I think it is in the 3 dots or under the comment and the right of the dots.

Good afternoon, body.

Yes, I just checked, everything works, but in any case I will analyze and improve your code!

1 Like

That’s the attitude, keep it up!

1 Like