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

How do I fix the sync on my welds?

Asked by 6 years ago
local play = game.Players.LocalPlayer
char = play.Character
hum = char.Humanoid
replogia = game.ReplicatedStorage.LogiaV2
--
head = char:WaitForChild("Head")
uppertorso = char:WaitForChild("UpperTorso")
lowertorso = char:WaitForChild("LowerTorso")
leftupperarm = char:WaitForChild("LeftUpperArm")
leftlowerarm = char:WaitForChild("LeftLowerArm")
lefthand = char:WaitForChild("LeftHand")
rightupperarm = char:WaitForChild("RightUpperArm")
rightlowerarm = char:WaitForChild("RightLowerArm")
righthand = char:WaitForChild("RightHand")
leftupperleg = char:WaitForChild("LeftUpperLeg")
leftlowerleg = char:WaitForChild("LeftLowerLeg")
leftfoot = char:WaitForChild("LeftFoot")
rightupperleg = char:WaitForChild("RightUpperLeg")
rightlowerleg = char:WaitForChild("RightLowerLeg")
rightfoot = char:WaitForChild("RightFoot")
--
headl = replogia.HeadLogia
uppertorsol = replogia.UpperTorsoLogia:Clone()
lowertorsol = replogia.LowerTorsoLogia:Clone()
leftupperarml = replogia.LeftUpperArmLogia:Clone()
leftlowerarml = replogia.LeftLowerArmLogia:Clone()
lefthandl = replogia.LeftHandLogia:Clone()
rightupperarml = replogia.RightUpperArmLogia:Clone()
rightlowerarml = replogia.RightLowerArmLogia:Clone()
righthandl = replogia.RightHandLogia:Clone()
leftupperlegl = replogia.LeftUpperLegLogia:Clone()
leftlowerlegl = replogia.LeftLowerLegLogia:Clone()
leftfootl = replogia.LeftFootLogia:Clone()
rightupperlegl = replogia.RightUpperLegLogia:Clone()
rightlowerlegl = replogia.RightLowerLegLogia:Clone()
rightfootl = replogia.RightFootLogia:Clone()
userinput = game:GetService("UserInputService")
KeyHeld = false


function onKeyPress(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.F then
        KeyHeld = true
        headl = replogia.HeadLogia
        uppertorsol = replogia.UpperTorsoLogia:Clone()
        lowertorsol = replogia.LowerTorsoLogia:Clone()
        leftupperarml = replogia.LeftUpperArmLogia:Clone()
        leftlowerarml = replogia.LeftLowerArmLogia:Clone()
        lefthandl = replogia.LeftHandLogia:Clone()
        rightupperarml = replogia.RightUpperArmLogia:Clone()
        rightlowerarml = replogia.RightLowerArmLogia:Clone()
        righthandl = replogia.RightHandLogia:Clone()
        leftupperlegl = replogia.LeftUpperLegLogia:Clone()
        leftlowerlegl = replogia.LeftLowerLegLogia:Clone()
        leftfootl = replogia.LeftFootLogia:Clone()
        rightupperlegl = replogia.RightUpperLegLogia:Clone()
        rightlowerlegl = replogia.RightLowerLegLogia:Clone()
        rightfootl = replogia.RightFootLogia:Clone()
        --
        while KeyHeld do
            headl.Parent = char
            uppertorsol.Parent = char
            lowertorsol.Parent = char
            leftupperarml.Parent = char
            leftlowerarml.Parent = char
            lefthandl.Parent = char
            rightupperarml.Parent = char
            rightlowerarml.Parent = char
            righthandl.Parent = char
            leftupperlegl.Parent = char
            leftlowerlegl.Parent = char
            leftfootl.Parent = char
            rightupperlegl.Parent = char
            rightlowerlegl.Parent = char
            rightfootl.Parent = char
            --
            headl.CFrame = head.CFrame * CFrame.new(0,0,0)
            local weld1 = Instance.new("Weld")
            weld1.Part0 = headl
            weld1.C0 = headl.CFrame:inverse()
            weld1.Part1 = head

            uppertorsol.CFrame = uppertorso.CFrame * CFrame.new(0,0,0)
            local weld2 = Instance.new("Weld")
            weld2.Part0 = uppertorsol
            weld2.C0 = uppertorsol.CFrame:inverse()
            weld2.Part1 = uppertorso

            lowertorsol.CFrame = lowertorso.CFrame * CFrame.new(0,0,0)
            local weld3 = Instance.new("Weld")
            weld3.Part0 = lowertorsol
            weld3.C0 = lowertorsol.CFrame:inverse()
            weld3.Part1 = lowertorso

            leftupperarml.CFrame = leftupperarm.CFrame * CFrame.new(0,0,0)
            local weld4 = Instance.new("Weld")
            weld4.Part0 = leftupperarml
            weld4.C0 = leftupperarml.CFrame:inverse()
            weld4.Part1 = leftupperarm

            leftlowerarml.CFrame = leftlowerarm.CFrame * CFrame.new(0,0,0)
            local weld5 = Instance.new("Weld")
            weld5.Part0 = leftupperarml
            weld5.C0 = leftupperarml.CFrame:inverse()
            weld5.Part1 = leftlowerarm  

            lefthandl.CFrame = lefthand.CFrame * CFrame.new(0,0,0)
            local weld1 = Instance.new("Weld")
            weld1.Part0 = lefthandl
            weld1.C0 = lefthandl.CFrame:inverse()
            weld1.Part1 = lefthand

            rightupperarml.CFrame = rightupperarm.CFrame * CFrame.new(0,0,0)
            local weld2 = Instance.new("Weld")
            weld2.Part0 = rightupperarml
            weld2.C0 = rightupperarml.CFrame:inverse()
            weld2.Part1 = rightupperarm

            rightlowerarml.CFrame = rightlowerarm.CFrame * CFrame.new(0,0,0)
            local weld3 = Instance.new("Weld")
            weld3.Part0 = rightlowerarml
            weld3.C0 = rightlowerarml.CFrame:inverse()
            weld3.Part1 = rightlowerarm

            righthandl.CFrame = righthand.CFrame * CFrame.new(0,0,0)
            local weld4 = Instance.new("Weld")
            weld4.Part0 = righthandl
            weld4.C0 = righthandl.CFrame:inverse()
            weld4.Part1 = righthand

            leftupperlegl.CFrame = leftupperleg.CFrame * CFrame.new(0,0,0)
            local weld5 = Instance.new("Weld")
            weld5.Part0 = leftupperlegl
            weld5.C0 = leftupperlegl.CFrame:inverse()
            weld5.Part1 = leftupperleg

            leftlowerlegl.CFrame = leftlowerleg.CFrame * CFrame.new(0,0,0)
            local weld1 = Instance.new("Weld")
            weld1.Part0 = leftlowerlegl
            weld1.C0 = leftlowerlegl.CFrame:inverse()
            weld1.Part1 = leftlowerleg

            leftfootl.CFrame = leftfoot.CFrame * CFrame.new(0,0,0)
            local weld2 = Instance.new("Weld")
            weld2.Part0 = leftfootl
            weld2.C0 = leftfootl.CFrame:inverse()
            weld2.Part1 = leftfoot

            rightupperlegl.CFrame = rightupperleg.CFrame * CFrame.new(0,0,0)
            local weld3 = Instance.new("Weld")
            weld3.Part0 = rightupperlegl
            weld3.C0 = rightupperlegl.CFrame:inverse()
            weld3.Part1 = rightupperleg

            rightlowerlegl.CFrame = rightlowerleg.CFrame * CFrame.new(0,0,0)
            local weld4 = Instance.new("Weld")
            weld4.Part0 = rightlowerlegl
            weld4.C0 = rightlowerlegl.CFrame:inverse()
            weld4.Part1 = rightlowerleg

            rightfootl.CFrame = rightfoot.CFrame * CFrame.new(0,0,0)
            local weld5 = Instance.new("Weld")
            weld5.Part0 = rightfootl
            weld5.C0 = rightfootl.CFrame:inverse()
            weld5.Part1 = rightfoot 
            wait()  
        end
    end
end

function onKeyRelease(inputObject,gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.F then
        KeyHeld = false
    end
end

game:GetService("UserInputService").InputBegan:Connect(onKeyPress)
game:GetService("UserInputService").InputEnded:Connect(onKeyRelease)

GIF of the problem https://gyazo.com/c2fac6cecb9b417a3c6ca929215be0cb

Basically, I've welded the parts individually to each limb of the character, but whenever I move the parts don't synchronize and are slightly delayed, anyway to fix this?

1 answer

Log in to vote
1
Answered by
xdeno 187
6 years ago
Edited 6 years ago

Instead of a while true do loop try adding this to your script.

This is called RenderStepped, you can read more here: https://wiki.roblox.com/index.php?title=API:Class/RunService/RenderStepped

It's simply faster than a while true do loop, it fires every render frame, which is approximately 1/60th of a second.

game:GetService("RunService").RenderStepped:connect(function()
    if KeyHeld = false then return end  

end)
0
Wow, that worked perfectly, thanks a-lot. nicktooner 119 — 6y
0
np xdeno 187 — 6y
Ad

Answer this question