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

Help with welds?

Asked by 9 years ago

I was wondering why isn't this script welding the player's arms to the cloned arms and cloning the left arm? If you manged to fix it please show how and what you did. I got no errors in the output.

game.Players.PlayerAdded:connect(function(Player)
        Player.CharacterAdded:connect(function(Character)
---------------------------------------------------------
            function MakeDisplayArms()
---------------------------------------------------------
                local CurrentCamera = game.Workspace.CurrentCamera
                local PlayerArms = {
                    Character["Right Arm"],
                    Character["Left Arm"]}
---------------------------------------------------------
                    for i,v in pairs (PlayerArms) do
                Character:WaitForChild(v.Name)
                FoundClonedArms = CurrentCamera:FindFirstChild("Cloned_"..v.Name)--Finds for Cloned parts
                if not FoundClonedArms then--Litte debounce
                        print(v)
                        local ClonedArms = v:Clone()
                        ClonedArms.Parent = CurrentCamera--Hides it from everyone else
                        ClonedArms.Name = "Cloned_"..v.Name --Renames it
                        ClonedArms.CanCollide = true
                        local Weld = Instance.new("Weld",v)
                            Weld.Part0 = ClonedArms--Welds it Arms
                            Weld.Part1 = v
                        return ClonedArms
                        else
                    return FoundClonedArms
                    end
                end
            end
---------------------------------------------------------           
           Arms = MakeDisplayArms()
            print(Arms)
        end)
end)

What is this script suppose to do? This script is suppose to make a fake arm that is hidden in the CurrentCamera and that the player can see his arm when zoomed in.

1 answer

Log in to vote
2
Answered by 9 years ago

I removed the debounce, because it's not needed. Then I moved the 'Return' outside the for loop. In your script, the for loop stopped after cloning the first arm. Then for the extra table, I made that one to hold the new cloned arms. So they can be returned as a table at the end of the function.

game.Players.PlayerAdded:connect(function(Player)
        Player.CharacterAdded:connect(function(Character)
---------------------------------------------------------
            function MakeDisplayArms()
    wait()
---------------------------------------------------------
                local CurrentCamera = game.Workspace.CurrentCamera
                local PlayerArms = {
                    Character["Right Arm"],
                    Character["Left Arm"]}
                local ClonedArms = {}
---------------------------------------------------------
                for i,v in pairs (PlayerArms) do
                    Character:WaitForChild(v.Name)
                    local Clone = v:Clone()
                    Clone.Parent = CurrentCamera--Hides it from everyone else
                    Clone.Name = "Cloned_"..v.Name --Renames it
                    Clone.CanCollide = true
                    local Weld = Instance.new("Weld",Clone)
                    Weld.Part0 = Clone
                    Weld.Part1 = v
                    ClonedArms[i] = Clone
                end
                return ClonedArms
            end
---------------------------------------------------------           
            Arms = MakeDisplayArms()
        end)
end)

Now for example

-- If you put:
print(Arms[2].Name.." and "..Arms[1].Name)
-- After:
Arms = MakeDisplayArms()

It will print Left Arm and Right Arm

0
How did you get the arms in the table if you didn't use Table.insert? kevinnight45 550 — 9y
1
The for loop gives an index, which in this case is 'i'. Then at Line 22 of the script above, you can see that I put the 'Clone' in the 'ClonedArms' table at index 'i'. damagex443 325 — 9y
Ad

Answer this question