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

How do I rotate a welded item on my torso?

Asked by 5 years ago
script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local playerName = hit.Parent.Name
    if humanoid then
        print(playerName.." is cool!")
        local torso = hit.Parent.Torso
    local weld = Instance.new("Weld")
    script.Parent.CFrame = torso.CFrame * CFrame.new(0, 0, 1, 90, 0, 0)
    weld.Part0 = torso
    weld.C0 = torso.CFrame:Inverse()
    weld.Part1 = script.Parent
    weld.C1 = script.Parent.CFrame:Inverse()
    weld.Parent = script.Parent
        script.Parent.Anchored = false
    end

end)

I understand how to do the position but for me, the thing I got confused on was the rotation of it. I attempted to add 3 numbers on to it for a rotation as I would in HTML but that didn't have any results.

0
When you rotate something that is welded with joints, the joints break. Therefore you gotta make new joints to keep the bodyparts together. Is that what you need help with, or am I totally wrong? c; TheWaterFoox 255 — 5y
0
I mean I'd assume but does that apply to it if it was a backpack I'm testing backpacks and other sorts of things that go around the torso? Untacked 10 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

instead of using Welds use WeldConstraints so the joint doesnt break when you try to rotate the connected parts. use CFrame.Angles() to rotate the part. also this would only work for R6 since R15 and rthro dont have torsos, instead you could use the HumanoidRootPart which is available on all avatars.

script.Parent.Touched:Connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    local playerName = hit.Parent.Name

    if humanoid then
        print(playerName.." is cool!")
        local torso = hit.Parent.HumanoidRootPart
        local weld = Instance.new("WeldConstraint")

        script.Parent.CFrame = torso.CFrame * CFrame.Angles(0,math.rad(90),0) -- rotates it by 90° 
    weld.Part0 = torso
    weld.Part1 = script.Parent
    weld.Parent = script.Parent
    script.Parent.Anchored = false
    end
end)
Ad

Answer this question