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

How would I prevent welded part teleporting away when rotated?

Asked by
deris88 146
6 years ago
Edited 6 years ago

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!

0
Based on what you sent me in the chat. Like this? http://prntscr.com/g9a43n Azarth 3141 — 6y
0
CFraming ignores welds and stuff. Try avoiding them. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago

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)
Ad

Answer this question