How can i weld a part to a player?

SO im trying to weld a part to a player but im not sure how, please help

local shield = game.ReplicatedStorage.shield:Clone()
game.Players.PlayerAdded:Connect(function(player)
 local character = player.Character or player.CharacterAdded:Wait()
		shield.Parent = character
	local weld = Instance.new("WeldConstraint")
	weld.Part0 = shield
	weld.Part1 = character.HumanoidRootPart
	weld.Parent = character
	shield.IsInUse.Value = true
end)



5 Likes
local shield = game.ReplicatedStorage.shield:Clone()
local player = game.Players.LocalPlayer
local character = player.CharacterAdded:wait() or workspace[player.Name]

spawn(function()
    local weld = Instance.new("Weld", part)
    weld.Part0 = shield
    weld.Part1 = character["Left Arm"]
    weld.C0 = CFrame.new(0, 0, 0) *CFrame.new(0, 0, 0) 
end)

Try this! :smiley:

1 Like

You can change the part2 weld to a part of the character.

attempt to index nil with character added

I updated the code and added a new variable. Try again?

it’s a serverscript

i tried this

local shield = game.ReplicatedStorage.shield:Clone()
local player = game.Players.PlayerAdded:Wait()
local character = player.CharacterAdded:Wait() or workspace[player.Name]

spawn(function()
	local weld = Instance.new("Weld", shield)
	weld.Part0 = shield
	weld.Part1 = character.HumanoidRootPart
	weld.C0 = CFrame.new(0, 0, 0) *CFrame.new(0, 0, 0) 
end)

no errors but nothing happened

Weird… thought that would work

Check in the explorer while play testing if the weld exists. The problem might be the positioning. With WeldConstraints, you can adjust the position and orientation with the .Position and .Orientation properties.

I’d recommend trying something like this:

local shield = game.ReplicatedStorage.shield:Clone()
game.Players.PlayerAdded:Connect(function(player)
 local character = player.Character or player.CharacterAdded:Wait()
		shield.Parent = character
	local weld = Instance.new("WeldConstraint")
	weld.Parent = character
	weld.Part0 = shield
	weld.Part1 = character.HumanoidRootPart
	sheild.Position = character.HumanoidRootPart.Position
	shield.IsInUse.Value = true
end)

To better position the Shield, you can add character.HumanoidRootPart.CFrame.LookVector * constant and character.HumanoidRootPart.CFrame.RightVector * constant to adjust the shield. You can also set the orientation of the shield to character.HumanoidRootPart.Orientation.

10 Likes

Another solution :partying_face:

Huh, if the player dies then the weld won’t be there when they respawn, I don’t really know how to fix that

Make the code a function, then listen to the Humanoid.Died signal with that function.

1 Like

Sorry, I’m kind of new to this, how do I make that work? I put my script in StarterCharacterScripts, idk if I should put it in ServerScriptService

You should watch tutorials on how to learn scripting on Roblox, there’s plenty of videos on Youtube about this.

I’m dumb, I figured it out shortly after posting that