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

Why is this weld position dependant on where your arms are when you join?

Asked by
DevingDev 346 Moderation Voter
5 years ago

I want the arms to be like the character is holding the "tool" in front of him but right now it works and all but it's dependant on where your arms are when the modulescript is called, Like if i would be falling from the sky my arms would not be as I would want them too. They would be all over the place.

This is how I would want them to be all the time, a.k.a how i've drawn the red part: https://imgur.com/a/08ClqcM

This is how they are currently if your character like jumps when the modulescript is called. https://gyazo.com/6b46d5ec3d45615a497c316d884c4b1e

Server script calling the modulescript:

local function SetupBackpacksAndTools(player)
    local Data = GetPlayerData(player)
    local Backpack = Data["Backpack"]
    local Tool = Data["Tool"]

    local NewTool = game.ReplicatedStorage.Tools[Tool]:Clone()
    local NewBackpack = game.ReplicatedStorage.Backpacks[Backpack]:Clone()

    player.Character:FindFirstChild("RightUpperArm").Name = "RightUpperArm1"
    player.Character:FindFirstChild("LeftUpperArm").Name = "LeftUpperArm1"

    WeldUtil.Location(player, NewBackpack, player.Character)
    WeldUtil.SetToolLocation(player, NewTool, player.Character)

    NewTool.Parent = player.Character
    NewBackpack.Parent = player.Character
end

Modulescript:

function Weld:SetToolLocation(Tool, char)
    local ArmCFrame = require(script:WaitForChild("ArmCFrame"))

    for i,v in pairs(Tool:GetChildren()) do -- welds the tool to the arms.
        if v:IsA("Model") then
            local weld = Instance.new("Weld", v.PrimaryPart)

            weld.Part0 = v.PrimaryPart
            weld.Part1 = char:WaitForChild("RightHand")

            weld.C0 = CFrame.new(1.5,0,-0.5) + ArmCFrame["Vacuums"][Tool.Name][1]
            weld.C1 = CFrame.fromEulerAnglesXYZ(-0.8, 4.1, -0)

            char.LeftUpperArm1.LeftShoulder.C1 = ArmCFrame["Arms"].LeftShoulderC1
            char.LeftUpperArm1.LeftShoulder.C0 = ArmCFrame["Arms"].LeftShoulderC0

            char.RightUpperArm1.RightShoulder.C1 = ArmCFrame["Arms"].RightShoulderC1
        end
    end
end

Answer this question