Welding object problem

Good evening everybody.I am trying to make a welding system when player is added so when the player dies it stops anyways here is my script

game.Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(Character)
		local HRP = Character:FindFirstChild("HumanoidRootPart")
		local Cover = script.Parent.Model:Clone()
		local weld = Instance.new("Weld")
		weld.Parent = Cover.Part
		weld.Part0 = Cover.Part
		weld.part1 = HRP
		script.Disabled = true
		script.Disabled = false
	end)
end)

Thanks for any help anyway.

I assume the script is for welding a model, something like a hat or an accessory that is automatically equipped when a player spawns. What is the issue? Does it not weld?

Well the issue is that when the player is added it works perfectly but on the player’s death it doesnt work.
what is more for giving more details:
-Its a Script not local script

-Its inside the ServerScriptService


You are trying to attach a new object (Cover) to the player’s HumanoidRootPart when it joins the game. However, you’re using the CharacterAdded event, which only triggers when the player is initially added.

Something better to do is at player death and respawn, use both PlayerAdded and Player.CharacterAdded events.

-- function to set up Cover and Weld for a player
local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function(character)
        local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

        -- create Cover and Weld it to the player's character
        local cover = script.Parent.Model:Clone()
        local weld = Instance.new("Weld")
        weld.Parent = cover.Part
        weld.Part0 = cover.Part
        weld.Part1 = humanoidRootPart

        -- ensure the script runs only once for each player
        script.Disabled = true
        script.Disabled = false
    end)
end

-- connect the function to the PlayerAdded event
game.Players.PlayerAdded:Connect(onPlayerAdded)

Thanks for your suggestion but sadly it didn’t work.

Could I see what happens? Does it go to your character and fall or does it never reach you?. It would also be good to know if any errors on the output appear.

I found an error after the play dies it says

ServerScriptService.Rapier cover.Script:2: attempt to index nil with ‘CharacterAdded’ - Server - Script:

Acctually when the play dies then spawn it seems to be not added

I overlooked the normal waiting for the character to load, which is probably what happened to you at first glance, I redid the script. Tell me if any errors appear

game.Players.PlayerAdded:Connect(function(Plr)
    local function ApplyWeldConstraints(Character)
        local HRP = Character:FindFirstChild("HumanoidRootPart")
        if HRP then
            local Cover = script.Parent.Model:Clone()
            local weldConstraint = Instance.new("WeldConstraint")
            weldConstraint.Parent = HRP
            weldConstraint.Part0 = HRP
            weldConstraint.Part1 = Cover.Part
            script.Disabled = true
            script.Disabled = false
        end
    end

    if Plr.Character then
        ApplyWeldConstraints(Plr.Character)
    end

    Plr.CharacterAdded:Connect(function(Character)
        ApplyWeldConstraints(Character)
    end)
end)


This looks like something you’re adding to the player at start. If this is something they are wearing you may be able to add that to Game Settings/Avatar … a bit lower in the interface you can force standard items for spawn.