Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why doesnt my object dragging script function correctly? [closed]

Asked by 6 years ago
local dragger = nil

local function GetBaseParts(obj)
    if obj:IsDescendantOf(moveable) then
        for i,v in pairs(obj.Parent:GetChildren()) do
            if v == obj.Parent then
                return {obj}
            end
            if i == #obj.Parent:GetChildren() and v ~= obj.Parent then
                local Table = {}
                for x,d in pairs(obj.Parent:GetChildren()) do
                    if d:IsA("BasePart") then
                        table.insert(Table, d)
                    end
                end
                return Table
            end
        end
    end
end

mouse.Button1Down:connect(function()
    pcall(function()
        if mouse.Target:IsDescendantOf(moveable) and TargetVal ~= nil and (TargetVal.Owner.Value == nil or TargetVal.Owner.Value == player.Name or TargetVal.Owner.Value == "") and (player.Character.UpperTorso.Position-mouse.Target.Position).magnitude <= Settings.MaxReachDistance then
            MousePos = "Down"
            SavedTarget = TargetVal
            game.ReplicatedStorage.Remotes.SetObjectOwner:FireServer(TargetVal)
            dragger = Instance.new("Dragger")
            local hitPoint = mouse.Hit:toObjectSpace(mouse.Target.CFrame).p
            local instances = GetBaseParts(mouse.Target)
            dragger:MouseDown(mouse.Target, hitPoint, instances)
        end
    end)
end)

There is no output errors (when i removed the pcalls, too) and the object doesnt move at all, any idea on how to fix this?

Closed as Too Broad by Goulstem

This question has been closed because it is too broad and is generally unanswerable. Please ask a more specific question.

Why was this question closed?