Doubts mouse properties

Hello, I would like to know if someone could give me a hand to learn how to use the following mouse properties → Hit, origin, target.

and as a practice I need:
I need to make a part appear in the mouse position and that it only be dragged on a specific basepale.

Any idea how to do it?

When the player clicks their mouse you can start by checking if the mouse.Target is a specific part, then if it is you allow the dragging part to be dragged to the mouse.Hit (but you may want to offset the position by the size of the part–mouse.Hit.Position +, Part.Size.Y / 2, 0) or something similar)

I don’t quite understand how to do that :frowning: I need to do that myself but I don’t know how

I would use RunService.RenderStepped event which fires before each frame

      -- Mouse.Target is the BasePart the mouse hit, if no BasePart it will return nil
      if mouse.Target == workspace.Baseplate then
          -- Mouse.Hit is the CFrame in 3d space that the mouse hits
          draggingPart.CFrame = Mouse.Hit
          -- you might want to add offset like @DrKittyWaffles said

Make sure to add the draggingPart to the mouse.TargetFilter so that mouse.Hit does not interact with draggingPart

1 Like

It might be more effective to use raycasting anyway this is how I would have
what he is trying to do set up

    -- construct ray
	local mouseRay = mouse.UnitRay
	local rayCastParams = 
	rayCastParams.FilterDescendantsInstances = {item,player.Character}
	rayCastParams.FilterType = Enum.RaycastFilterType.Blacklist

    -- cast ray
	local raycastResult = game.Workspace:Raycast(mouseRay.Origin,mouseRay.Direction.unit * MAX_PLACEMENT_DISTANCE,rayCastParams)

	if raycastResult then
		target = raycastResult.Instance:GetFullName() -- BasePart ray hit
		pos = raycastResult.Position -- Vector3 Position ray hit
		norm = raycastResult.Normal -- surface normal ray hit
		local endPos = pos + (norm * (item.PrimaryPart.Size*.5)) -- this math will offset the part so they don't intersect
		item:SetPrimaryPartCFrame( -- set draggingpart CFrame 
1 Like