One of my welds is instantly breaking

So I have a function in my game that welds a gun model to the character’s hands when they spawn. Two days ago it was working fine, but now it does not work. Now, when I try and weld the gun model to the character, all of the welds that hold the gun model together work just fine, but the one weld that connects the gun model’s primary part to the character’s hand is immediately destroyed as soon as it is created.

The only difference between my code two days ago and my code now is that the welding function is now called when the player chooses their loadout and teleports into the map rather than calling the welding function as soon as they respawn.

None of my code deletes any welds (as far as I can see, anyway) or adds them to the Debris service.

Does anyone have any ideas about what might be going on or problems I should look for?

2 Likes

Does your script Weld then Unanchor? Try anchoring your gun and then when the player uses quickly welding them all and unanchor them

2 Likes

I believe this is the exact issue you’re currently having, the solution is also on this thread!

https://devforum.roblox.com/t/why-do-welds-break-when-equipping-a-tool-and-how-do-i-stop-this-for-complex-tools-solved-at-last/10804?u=infinitumfrost

@iRexBot
The parts are initially anchored, then welded, and then unanchored.

@InfinitumFrost
Reparenting doesn’t seem to be the problem. If I parent the gun model to the player and then weld it, the same problem occurs.

1 Like

Does your script weld a part then unanchor that part? Try welding all the parts then once they’re all welded unanchor them all.

When a character spawns, they have an initial set of body parts on CharacterAdded that can be destroyed and replaced by their avatar package parts. Final parts are available to reference on CharacterAppearanceLoaded. If you weld to the temporary hand, the weld will break. This is just one possible cause of this in a Roblox game.

Also, you have to make the weld in a server Script, not LocalScript, just FYI.

1 Like

That doesn’t solve the problem either.

1 Like

The welding occurs well after the player has actually respawned, so that shouldn’t be the problem. In fact, the only time the script works properly is when the welding occurs as soon as the character respawns.

The welding is handled by a server script after it verifies that the loadout the player selected is valid.

It would definitely help to see the relevant section of code in some context. It should be no trouble to weld a part to a character at any time on the server. But deleting the weld isn’t the only thing that can break it: anything trying to set position or orientation of one of the welded parts will break the weld. Are there scripts in the gun? What else is happening to the character at this time, and have you disabled everything after the weld is created to check that it’s not something to do with the teleport? How is the gun created? Have you tried replacing the gun with just a single part to diagnose?

I figured it out. The problem was that I was welding the gun model to the character’s hands and then teleporting them. Since I store the gun models in a folder separately from the characters, the gun model was not being teleported with the character, breaking the welds. All I needed to do to fix the problem was teleport the player before welding the gun model.

1 Like

Hmm. What mechanism is your “teleport” based on? I weld things to characters in my games, before and after they are parented to the Workspace, and I “teleport” players with weapons around via SetPrimaryPartCFrame. The weapon will stay with them no matter where it’s parented under workspace (in a folder is no problem), but of course I usually put them inside the character model because this is convention.

1 Like

Ah. I usually use MoveTo for teleportation. I’ll have to give SetPrimaryPartCFrame a shot. That’ll also solve any potential “spawning on the roof” situations.

1 Like