Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I rotate a welded item on my torso?

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.

2 comments

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;

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?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.