I’m trying to fix a bug where when I drag an object using Drag Detector, the object doesn’t move at all since I’m using a ROBLOX Physics Instances (align position). Why is that? I watched a 2024 tutorial on how to initialize Drag Detector to follow Camera, but it seems like that video (for some odd reason is deprecated) …
I also read this post: Roblox seems to have broken DragDetector.DragContinue? - Help and Feedback / Scripting Support - Developer Forum | Roblox
but that didn’t help my issue.
Here’s the instances that are created;
function ItemModule:createObjectMover(obj: BasePart): AlignPosition
local posAtt = Instance.new("Attachment")
posAtt.Parent = obj
local alignPosition = Instance.new("AlignPosition")
alignPosition.Parent = obj
alignPosition.Attachment0 = posAtt
alignPosition.Enabled = false
alignPosition.Responsiveness = 100
return alignPosition
end
function ItemModule:createDragDetector(obj: BasePart): DragDetector
local dragDetector = Instance.new("DragDetector")
dragDetector.Parent = obj
dragDetector.MaxActivationDistance = 10
dragDetector.DragStyle = Enum.DragDetectorDragStyle.Scriptable
dragDetector.PermissionPolicy = Enum.DragDetectorPermissionPolicy.Scriptable
dragDetector.ResponseStyle = Enum.DragDetectorResponseStyle.Custom
dragDetector.Responsiveness = 100
dragDetector.ApplyAtCenterOfMass = true
return dragDetector
end
and here’s the drag detector events:
function ItemModule:connectDragEvents()
local dragDetector = self.dragDetector
self._janitor:Add(dragDetector.DragStart:Connect(function(player: Player)
local playerBackpack = BackpackService:GetBackpack(player)
self.item:SetNetworkOwner(player)
local att = self:getLookAt(player)
if att then
self.item.CanTouch = false
task.delay(.1, function() self.item.CanTouch = true end)
playerBackpack.selectedItem = self.item
self.alignPosition.Attachment1 = att
self.alignPosition.Enabled = true
self.item:SetAttribute("CurrentDrag", player.UserId)
end
end), "Disconnect")
self._janitor:Add(dragDetector.DragContinue:Connect(function(player: Player, _, viewFrame: CFrame)
local playerBackpack = BackpackService:GetBackpack(player)
local att = self:getLookAt(player)
local char = player.Character
if att then
playerBackpack.selectedItem = self.item
local Y = viewFrame.LookVector.Y
att.CFrame = CFrame.new( Vector3.new(0, (Y * 5), -5) )
end
-- // do magnitude checking
local distance = (self.item.Position - char.PrimaryPart.Position).Magnitude
if distance > dragDetector.MaxActivationDistance then
playerBackpack.selectedItem = nil
self.alignPosition.Enabled = false
self.alignPosition.Attachment1 = nil
self.item:SetAttribute("CurrentDrag", nil)
if self.item and self.item.Parent then self.item:SetNetworkOwner(nil) end
end
end), "Disconnect")
self._janitor:Add(dragDetector.DragEnd:Connect(function(player: Player)
local playerBackpack = BackpackService:GetBackpack(player)
playerBackpack.selectedItem = nil
self.alignPosition.Enabled = false
self.alignPosition.Attachment1 = nil
self.item:SetAttribute("CurrentDrag", nil)
if self.item and self.item.Parent and not self.item.Anchored then self.item:SetNetworkOwner(nil) end
end), "Disconnect")
dragDetector:SetPermissionPolicyFunction(function()
if not self.item:GetAttribute("CurrentDrag") then
return true
end
return false
end)
end
any help would be appreciated!