How do you create a weld to the player with a script?

How do you create a weld from a part to the player using a script? I am not very familiar with how it works.
I am making a custom forcefield that you spawn in with when you join or reset. I want the forcefield part to be moving along with the player when they walk.

You can generate the weld and it’s and instance using Instance.new()

I’ll recommend you to use a weld constraint as a normal weld would override the CFrame regarding which part you declare as Part0

Example

local weld = Instance.new("WeldConstraint")

-- You would then parent the weld to the player
Weld.Parent = -- Your Player Instance

--And Declare both Part0 and Part1 One being a Players Body Part and the other Being the Forcefield.

Weld.Part0 = -- Whatever body pat you want to use for the player Preferably[ Humanoid Root Part]
Weld.Part1 = -- Your Forcefield
3 Likes

You will most likely have to create these welds server-side, in your case using player.CharacterAdded event. Here is the post you might find useful that encompasses pretty much everything you need:

1 Like