Part can clip through walls when being dragged

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I am trying to make a dragging system similar to those in burger games like “Burger game” and “Cook burgers”

  2. What is the issue? The part can clip through walls which could cause some problems with trolls.

Trying mouse.hit only makes a worse problem
Here is part of the script that makes this system

	if input.UserInputType == Enum.UserInputType.MouseButton1 and not pickedUpPart then
		if (mouse.Hit.Position - character.Head.CFrame.Position).magnitude < 10 then
			if mouse.Target then
				if mouse.Target.Anchored == false then
					-- Pickup part
					pickedUpPart = true
					part = mouse.Target
					part.Anchored = true
					mouse.TargetFilter = part
					local connection
					connection = game:GetService("RunService").RenderStepped:Connect(function()
						if not pickedUpPart then mouse.TargetFilter = nil connection:Disconnect() return end
						local loc =, mouse.Hit.Position)
						part.Position = (loc + (loc.LookVector*10)).Position
						part.Orientation =,0,0)

I would like to know how to make so when the part hits a wall, it just sticks around instead of clipping.

1 Like

are you using raycast to find out the position it should be in? just detect what surface of a part it is touching and offset it by the correct amount for that ill give u code in 1 sec if i can find some in my old project

ok, but how would the offset be calculated tho? Also it doesn’t look like a raycast, but a cframe location with the direction pointing to mouse.hit and the position would be modified by its lookvector.

sorry for the wait just made a quick code demo by putting together some code i found in old projects

local target,pos,norm = nil
local MaxPlaceDistance = 50
local mouse = game.Players.LocalPlayer:GetMouse()
local part ="Part",workspace)
part.BrickColor ="Lime green")
part.Anchored = true
part.Transparency = 0.5
part.CanCollide = false

function UpdatePosition()
	local ignoreList = {game.Players.LocalPlayer.Character}
	if part ~= nil then
	local mouseRay = mouse.UnitRay
	local newRay =, mouseRay.Direction.Unit * MaxPlaceDistance)
	target, pos, norm = workspace:FindPartOnRayWithIgnoreList(newRay, ignoreList)

	local endPos = pos + (norm * (part.Size * 0.5))
	part.Position = endPos

put this in a local script in startergui or some other service that runs local scripts and you will see that it works well and you can take the code out and implement it into ur system

1 Like

I tinkered around with the norm and part.size/2 and the problem is solved now. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.