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

How would I prevent welded part teleporting away when rotated?

Hello.

So I have a model that has a part that is welded to a base part. (C0 - basepart, C1 - part) When I do weld.C0 = CFrame.Angles(math.rad(90), 0, 0) the part does rotate but teleports far away from the base part. None of wiki pages helped me. I tried using CFrame:inverse() but that did not help at all. I tried using Motor6D but effect is the same: part is teleported away. I also tried switching C1 and C0 but that did not help either.

Any help is highly appreciated!

2 comments

0

Based on what you sent me in the chat. Like this? http://prntscr.com/g9a43n

0

CFraming ignores welds and stuff. Try avoiding them.

1 answer

✓ Accepted answer

He posted a model in the chat, so this is based on that.

-- Taken from free models, cause yours wasn't working right. 
local all,last = {}
function scan(p)
	for _,v in pairs(p:GetChildren()) do
		if (v:IsA("BasePart")) then
			if (last) then
				local w = Instance.new("Weld")
				w.Part0,w.Part1 = last,v
				w.C0 = v.CFrame:toObjectSpace(last.CFrame):inverse()
				w.Parent = last
			end
			table.insert(all,v)
			last = v
		end
		scan(v)
	end
end
scan(script.Parent)
for _,v in pairs(all) do v.Anchored = false end 

Your second script, I reccomend using a RemoteEvent to fire after the weld script is done, so you don't have to wait 2 seconds. That or just put this part after the for loop in the weld script.

wait(2)
local base = script.Parent:WaitForChild('Base')
local weld = base:WaitForChild("Weld")
weld.C0 = CFrame.Angles(math.rad(90), 0,0)

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