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

How to rotate an accesory?

Asked by
bluzorro 417 Moderation Voter
4 years ago
Edited 4 years ago

Hello. I'm trying to make a backpack that should stay behind the player's torso (using R6).

Here's the script:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        local backpack = game.ServerStorage.Backpack

        backpack:Clone().Parent = char
        local torso = char.Torso        

        local weld = Instance.new("WeldConstraint", backpack)
        weld.Part0 = torso
        weld.Part1 = backpack.Handle
    end)
end)

Problem The backpack won't rotate so that it stays on the player's back, instead it looks like this:

Photo

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago

You need to modify the CFrame of the weld. In your case (and I think most cases), you want to modify weld.C0(CFrame0, like Part0). Because your backpack's back-to-front, you want to rotate it 180 degrees on the Y axis. If you're familiar with CFrames, you can probably do this yourself, but in case not, you'll want to use CFrame.Angles like so: weld.C0 = weld.C0 * CFrame.Angles(0, math.rad(180), 0) If you need to reposition it, add a Vector3 value: weld.C0 = weld.C0 + Vector3.new(x, y, z)

EDIT: Sorry - I didn't notice you were using a WeldConstrains as opposed to a regular weld. If it's the same to you, just use a regular weld, as you can set the CFrame for them.

Ad

Answer this question