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
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)
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 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.