How to weld a part to a player properly?

I’m trying to make a forcefield part around a player’s torso, welding it to the torso, but when making the weld and assigning it to the parts, the player gets teleported away with the forcefield for some reason. Is there any way to fix this?

This is my code:

local ff = Instance.new("Part",plr.Character.Torso)
ff.BrickColor = BrickColor.new("Electric blue")
ff.Transparency = 0.7
ff.CanCollide = false
ff.Size = Vector3.new(10,10,10)
ff.Shape = Enum.PartType.Ball
ff.Name = "FF"
local weld = Instance.new("Weld",plr.Character.Torso)
ff.Position = plr.Character.Torso.Position
weld.Part0 = plr.Character.Torso
weld.Part1 = ff
weld.C0 = plr.Character.Torso.CFrame
weld.C1 = ff.CFrame
weld.Name = "FFWeld"
5 Likes

looks like you forgot to cframe the forcefield to the character torso . The game might be teleporting the character to the forcefield cuz of that. Also I recommend Weld Constraints instead of weld

4 Likes

Is the forcefield Part somehow Anchored?

Why not just use a Roblox ForceField?

3 Likes

I set the position of the forcefield to the position of the torso already.

2 Likes

No, the forcefield is not anchored. And secondly, I cannot use the Roblox forcefield because the purpose of my forcefield is to keep other players out of it (and thus away from the player).

maybe weld it to the humanoidrootpart?

I could try that, but I don’t see how it’d make any difference.

The part that moves during welding is the part that is not the root part. Try increasing the root priority of the hrp

you fan try anchoring thr player in place when wleding the ff to the char

And how exactly would I do that?

char.Torso.RootPriority = 100
sjsjdjsb

1 Like

Just use a WeldConstraint. Please.

Also: don’t use the second parameter of Instance.new() unless you’re on the client. It’s a code smell.

local char = plr.Character

local ff = Instance.new("Part")
ff.BrickColor = BrickColor.new("Electric blue")
ff.Transparency = 0.7
ff.CanCollide = false
ff.Size = Vector3.new(10,10,10)
ff.Shape = Enum.PartType.Ball
ff.Name = "FF"
ff.CFrame = char:GetPivot() -- set position
ff.Parent = char.Torso      -- set parent after setting all properties

local weld = Instance.new("WeldConstraint")
weld.Part0 = char.Torso
weld.Part1 = ff
weld.Parent = ff

-- boom

why not use second argument? It make the code neater

1 Like

I understand how that might be logical, but it’s a bad practice for networking reasons. Here you’re setting 8 properties AFTER setting the parent. This means that you might get the instance replicated and then have the 8 property changes individually replicated to all clients.

This creates a lot of network traffic. When you set the parent last, the client wouldn’t know about the new Instance, as it lives in the server’s nil. Only when you’ve set everything up about the Instance, it can travel all at once to the client.

As a side note, creating Instances where you don’t modify properties right after creation can be 100% done with the second argument, I do it all the time.

3 Likes

oh did not know that! Ty
shddbdk

Just tried this and it doesn’t work; the character still gets teleported to the sphere, falling into the void with it.

Have you tried swapping Part0 and Part1? So have the torso be P1

Tried that, the player still gets teleported.