Physics/weld issue with my part move script

Edit: I think I found the source of the bug, it seems like the whole model is frozen in space, until I select the part that contains all the motor6D’s connecting the structure together. Once I select that part, and then try to move the model. It fixes it self? bug welds - YouTube

Any idea how to fix this?

So I’ve got a script that when you click a part. Will create a part call it “moverBall”

And I will weld the moverBall to the part I clicked. And then I every frame update moverBall to move towards my mouse position + slightly in front of the characters direction a few studs.

And it works, but it only works once I fiddle around with the physics it seems. It’s like there is an invisible weld with the model and the ground. And only once I’ve moved the object and messed with it’s physics does this script want to work properly.

I’ve disabled: join surfaces in the model tab. And it had no effect, there is no extra welds that I added between the model and the ground. The only welds are (the model which is just welding all it’s own parts to itself) and then my weld I create between the moverBall and the part selected.

This shows an example:

Script:

local CAS = game:GetService("ContextActionService") 

local GrabObject = nil
local GrabStart = false
local Dragger = nil


local player = game.Players.LocalPlayer
local character = player.Character
local mouse = player:GetMouse()
local camera = game.Workspace.CurrentCamera

function Grab(actionName, UserInputState, InputObject)
    if actionName == "Grab" then
        if UserInputState == Enum.UserInputState.Begin then
            -- start grab
            local Magnitude = (mouse.Hit.Position - character.Head.CFrame.Position).magnitude
            if Magnitude < 10 then
                if mouse.Target then
                    GrabObject = mouse.Target
                    GrabStart = true
                    local DragBall = createDragBall()
                    DragBall.CFrame = mouse.Hit
                    Dragger = DragBall
                    mouse.TargetFilter = GrabObject
                    local DragBallWeld = weldBetween(DragBall,GrabObject)
                    addMover(DragBall)
                   
                    while Dragger do
                        --Create a ray from the users head to the mouse.

                        local cf = CFrame.new(character.Head.Position, mouse.Hit.Position)
                        Dragger.Mover.Position = (cf + (cf.LookVector * 10)).Position
                        Dragger.RotMover.CFrame = camera.CFrame * CFrame.Angles(Dragger.RotOffset.Value.X,Dragger.RotOffset.Value.Y, Dragger.RotOffset.Value.Z)
                        wait()
                    end

                    mouse.TargetFilter = nil
                end
            end

        elseif UserInputState == Enum.UserInputState.End then

            -- stop grab
            GrabObject.Transparency = .5
            GrabObject = nil                    
            GrabStart = false
            if Dragger then
                Dragger:Destroy()
                Dragger = nil
            end
        end
    end
end

  

function weldBetween(a, b)
    local weld = Instance.new("ManualWeld", a)
    weld.C0 = a.CFrame:inverse() * b.CFrame
    weld.Part0 = a
    weld.Part1 = b
    return weld
end

 

function addMover(part)
    local newMover = Instance.new("BodyPosition")
    newMover.Parent = part
    newMover.MaxForce = Vector3.new(40000,40000,40000)
    newMover.P = 40000
    newMover.D = 1000
    newMover.Position = part.Position
    newMover.Name = "Mover"

    local newRot = Instance.new("BodyGyro")
    newRot.Parent = part
    newRot.MaxTorque = Vector3.new(3000,3000,3000)
    newRot.P = 3000
    newRot.D = 500
    newRot.CFrame = game.Workspace.CurrentCamera.CFrame
    newRot.Name = "RotMover"   

    local RotOffset = Instance.new("CFrameValue")
    RotOffset.Name = "RotOffset"
    RotOffset.Parent = part
end

  

function createDragBall()
    local DragBall = Instance.new("Part")
    DragBall.BrickColor = BrickColor.new("Electric blue")
    DragBall.Material = Enum.Material.Wood
    DragBall.Size = Vector3.new(.2,.2,.2)
    DragBall.Shape = "Ball"
    DragBall.Name = "DragBall"
    DragBall.Parent = workspace
    return DragBall
end

CAS:BindAction("Grab", Grab, false, Enum.UserInputType.MouseButton1)

Anyone any ideas? Please
////////////////

You probably shouldnt make 3 other posts on the topic and write a more concise report on the issue, even the video and script ia enough.

In this case it seems to be a network ownership issues since it only begins to move when you touch it (Network owner automatically transfers when close to an unanchored object)

Set network owner to the player on the server on grab:

I’ve never done that before, how do I transfer network ownership?

And my other posts were different questions, although pertaining to the same thing.

On a grab action fire a remote to the server with the part you want to drag as a parameter.

RemoteEvent:FireServer(somePart)

Then OnServer event set the network ownership of the part, be warned that it is exploitable so you will add some sanity checks like making sure the part is close enough to the player and able to be dragged.

remoteEvent.OnServerEvent:Connect(function(player,somePart)
somePart:SetNetworkOwner(player)
end)
1 Like

Okay, in my case the part in question is also welded to other parts. Would this matter? Or just the part that is being moved needs to have the network owner set?

Looks like it’s working, thanks a lot. I never would of known to do this :smiley:

If I did this via server script though instead of all on the client. Would I still need to do this networkownership? Or was this mainly an issue since it was all client manipulation?

It was an issue because you used physics on the client with any sort of BodyMovers or .AssemblyLinearVelocity changes.

Only one part per assembly (Assembly is a bunch of parts welded together) needs network ownership.

1 Like

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