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

What am I doing wrong with this weld and CFrame?

Asked by 6 years ago

The part named "Cargo" is supposed to be welded to a part called CargoHolder in the ship when it touches the ship's hull. It welds, but the cargo's CFrame is supposed to be set to the CFrame of CargoHolder. Instead it appears about 200 studs away from the ship and the CargoHolder part.

In other words, Cargo's CFrame needs to be set to CargoHolder's CFrame, and two studs above. What do I do?

ship = script.Parent.Parent
hull = ship.Hull
hull.Touched:connect(function(cargo)
    if cargo.Name == "Cargo" and cargo.ClassName == "Part" then

        local cargoWeld = Instance.new("Weld",ship.CargoHolder)
        cargoWeld.Name = "CargoWeld"
        cargoWeld.Part0 = ship.CargoHolder
        cargoWeld.Part1 = cargo
        cargoWeld.C0 = ship.CargoHolder.CFrame:inverse()
        cargoWeld.C1 = cargo.CFrame:inverse()
        cargo.CFrame = ship.CargoHolder.CFrame * CFrame.new(0,2,0)
        print("cargo attached to CargoHolder")

    end
end)
0
You don't have to do what I say,but a great way to have less lag in your game is by deleting the second parameter in Instance.new(), then after you doing the properties, do instanceName.Parent = the parent of the instance(The second parameter of Instance.new is deprecated. If you don't change any properties, you can use the second parameter), another thing I recommend to do is to get into the habi saSlol2436 716 — 6y
0
Use addition, not multiplication with a Vector3. hiimgoodpack 2009 — 6y
0
So like cargo.CFrame = ship.CargoHolder.CFrame + Vector3.new(0,2,0)? Jesse1240 59 — 6y
0
And thanks for telling me about the second parameter in Instance.new, that helps. Jesse1240 59 — 6y
0
I switched lines 10 and 11, so cargoWeld.C0 = cargo.CFrame:inverse() cargoWeld.C1 = ship.CargoHolder.CFrame:inverse() and now the cargo is set to the position of CargoHolder. But it needs to be 2 studs higher. Jesse1240 59 — 6y

Answer this question