Help with making collisions for drag detectors

Ok so I have a drag detector which I only want to move up and down

however it would go straight through objects. So I made this code which would add collision to it

local function CanMoveDirection(axis,d)
	
	local TouchingParts = game.Workspace:GetPartBoundsInBox(script.Parent.CFrame,script.Parent.Size)
	
	if table.find(TouchingParts,script.Parent) then
		table.remove(TouchingParts,table.find(TouchingParts,script.Parent))
	end
	
	print(TouchingParts)
	
	for i,v in pairs(TouchingParts) do
		
		--print(v.Position[axis] < script.Parent.Position[axis], "less")
		--print(v.Position[axis] > script.Parent.Position[axis], "greater")
		
		if d == true then
			if v.Position[axis] > script.Parent.Position[axis] then
				--print("Is greater")
				return false
			end
		end
		
		if d == false then
			if v.Position[axis] < script.Parent.Position[axis] then
				--print("Is less")
				return false
			end
		end
		
	end
	
	return true
end


script.Parent.DragDetector.DragContinue:Connect(function(player, cursorRay)
	-- Get the object being dragged
	local target = script.Parent
	
	-- Check if the object can move in the direction of the cursor ray
	local d = cursorRay.Direction.Unit.Y > 0
	
	local canMove = CanMoveDirection("Y",d)

	-- If the object can move, change its position
	
	
	if canMove then
		--print("Can go")
		LastC = target.Position
	else
		--print("Failed")
		target.Position = LastC
		
	end
end)

This works great as you can see in the video
however at the end it clipped through the baseplate for no reason. I have done all the debugging and nothing was wrong. Looked around the devforum already but found no solution. Any help would be very appreciated

Fixed it by making the MaxDrag translation 1 and the MinDrag translation -1

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