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

How do i create a moving tool that interacts with other parts correct?

Asked by 8 years ago

Hello, i am trying to make something that allows a player to move parts around with just moving their mouse, but when i do this the part that they move does not interact correctly. I have been getting the size of the part they are touching but this does not always work. How can i make this better.

v.MouseButton1Click:connect(function()
        if not activated2 then
            activated2 = true

        local clicked = false
        local tag = nil
        local untag = nil

        if tag == nil then
         model = Instance.new("Model")
            model.Name = v.Name model.Parent = game.Workspace
         clone = game.ReplicatedStorage.CopyItems:FindFirstChild(v.Name):Clone()
            clone.Parent = model
        end
        tag = model
        repeat
            wait(.1)
            if mouse.Target ~= nil and clone:IsA("Part") then
                tag.PrimaryPart = clone
            elseif mouse.Target ~= nil and clone:IsA("Model") then
                tag.PrimaryPart = clone:FindFirstChild("Base")
            end

            if mouse.Target ~=nil then
            tag:SetPrimaryPartCFrame(CFrame.new(math.ceil(mouse.Hit.X -tag.PrimaryPart.Size.X),math.ceil(mouse.Target.Position.Y + tag.PrimaryPart.Size.Y/2 + 1),math.ceil(mouse.Hit.Z +tag.PrimaryPart.Size.Z-.5)))
            end
            mouse.Button1Down:connect(function()
                if not activated then
                    activated = true

                    local Item = nil
                    if P:WaitForChild("Inventory"):FindFirstChild(v.Name) ~= nil then

                    local Item = P:WaitForChild("Inventory"):FindFirstChild(v.Name)
                    Item.Value = Item.Value -1
                        if v:FindFirstChild("Valued") ~= nil then
                            v.Valued.Text = Item.Value
                        end
                    if Item.Value < 0 then
                        v:Destroy()
                        model:Destroy()
                    end
                    if Item.Value == 0 then
                        v:Destroy()
                        Item:Destroy()
                    end

                    activated2 = false
                    clicked = true

                    end
                    local Item = nil
                    wait(.25)
                    activated = false
                end
            end)


        until   clicked == true
        clicked = false
        end
    end)

Answer this question