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

Welding Part to R6 Arm does not work properly?

Currently, I am attempting to weld a melee weapon handle to the left arm of my character. However, when i run the code in game, the weld does not go through. Is it because of the wording of Left Arm in my script? If so, how do I correct this fault?

game.ReplicatedStorage.Manifest.OnServerEvent:Connect()

local Players = game:GetService("Players")
local function OnPlayerAdded(Client)
 local Part = game.Workspace.Scythe.Handle
 local Weld = Instance.new("WeldConstraint")
 if Client.Character then
  wait(0.5)
  Part.Position = Client.Character["LeftArm"].Position
  Part.Orientation = Client.Character["LeftArm"].Orientation
  Weld.Parent = Client.Character
  Part.Parent = game.Workspace
  Weld.Part0 = Client.Character["LeftArm"]
  Weld.Part1 = Part
 else
  Client.CharacterAdded:Connect(function()
   wait(0.5)
   Part.Position = Client.Character["LeftArm"].Position
   Part.Orientation = Client.Character["LeftArm"].Orientation
   Weld.Parent = Client.Character
   Part.Parent = game.Workspace
   Weld.Part0 = Client.Character["Left Arm"]
   Weld.Part1 = Part
  end)
 end
end

Players.PlayerAdded:Connect(OnPlayerAdded)

1 answer

Yes, it is the wording. There's also a couple things to note:

  1. use Client.CharacterAdded:Wait() instead of Client.CharacterAdded:Connect(function) since Client.CharacterAdded:Wait() just pauses until an event is fired instead of running code every time the event is fired.

  2. How welds work is that they force an offset on two parts. If you want to change their positioning, use weld.C0

  3. Also use WaitForChild() instead of wait(0.5) as WaitForChild() waits until a child is available which can be faster and likely won't cause an error if you're in a laggy server.

game.ReplicatedStorage.Manifest.OnServerEvent:Connect()

local Players = game:GetService("Players")
local function OnPlayerAdded(Client)
 local Part = game.Workspace.Scythe.Handle
 local Weld = Instance.new("WeldConstraint")
 if Client.Character then
  Part.Position = Client.Character:WaitForChild("Left Arm").Position
  Part.Orientation = Client.Character["Left Arm"].Orientation
  Weld.Parent = Client.Character
  Part.Parent = game.Workspace
  Weld.Part0 = Client.Character["Left Arm"]
  Weld.Part1 = Part
 else
  Client.CharacterAdded:Wait()
  Part.Position = Client.Character:WaitForChild("Left Arm").Position
  Part.Orientation = Client.Character["Left Arm"].Orientation
  Weld.Parent = Client.Character
  Part.Parent = game.Workspace
  Weld.Part0 = Client.Character["Left Arm"]
  Weld.Part1 = Part
 end
end

Players.PlayerAdded:Connect(OnPlayerAdded)

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