[unsolved] How To Attach MeshPart to Player when ScreenGui Button is Clicked

Hey everyone,

I’ve been trying to make a locker system and I have no idea how to attach this nametag (MeshPart) when a player clicks a button on a ScreenGui. I’ve been trying everything and I still have no idea how to attach it. (i’ve been searching all over the devforum and other sites) Do any of you have any ideas?


image

2 Likes

This is how I would do it: Create a model with one part named “Middle” or something doesnt matter. The “Middle” part is going to be in the center of the Torso (or the part the model should be attached to). Set the middle part to the Primary Part of the model. Offset the meshpart to the right position and create a Weld Constraint. Part 0 is “Middle” and Part 1 is the Mesh Part. Place the model in Replicated Storage.
And create a remote event.
In the local script use RemoteEvent.FireServer()
In the serverScript:

local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Event")
local meshPart = RS:WaitForChild("MeshPart")
event.OnServerEvent:Connect(function(Player)
     local Character = Player.Character
  local newMeshPart = meshPart:Clone()
       local wc = Instance.New("WeldConstraint", newMeshPart)
       newMeshPart.Parent = Character:FindFirstChild("Torso")
       wc.Part0 = Character:FindFirstChild("Torso")
wc.Part1 = newMeshPart.PrimaryPart
newMeshPart.PrimaryPart.CFrame = Character:FindFirstChild("Torso").CFrame
end)

The cloning part needs to be in a server script if you want it to be visible to other players

3 Likes

image
There seems to be an error, could be because I placed something wrong, here’s quickly how I put it together:
image
(i put the weldconstraint correctly and in the local script it just fires the event and passes on the player)

1 Like

Can’t you just weld that thing to the player torso?


and to get the C0 of weld, just take NameTag.Position - Torso.Position

And then keep that weld somewhere.

When player click your gui thingy, just clone the weld.

And replace Part0 with the player’s torso and Part1 with the cloned nametag ( after that, also enable the cloned weld cuz it might automatically disable itself)

Then place the cloned weld and cloned nametag anywhere in the workspace and done (I recommend putting it inside the player character model obviously)

1 Like

Here’s an example
image


My character was R15 so I welded it to the UpperTorso instead of Torso

1 Like

There’s a couple of ways. One way is to weld the name tag onto the upper torso using the weld class. This requires setting the C0 and C1 CFrames of the weld though. Another way is to parent an Attachment to the name tag and use a WeldConstraint. Then you can use the predefined attachments of the character to attach the name tag to the player. To set the position, you move the name tag attachment around like you would a part. This is probably the easiest way to do it.

Try setting the parent to torso.BodyFrontAttachment and playing with the positions a little

You can detect when the button is clicked, then fire a RemoteEvent, then in a server script, check when the remote is fired, and when it gets fired, a server script will clone the mesh, and weld it to the torso using a WeldConstraint, then fiddle with the C0 til you get a position of your liking.

Just saw whats wrong the meshpart needs to be inside of the model. I also realised there is something wrong with the script.

local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("Event")
local model = RS:WaitForChild("Model")
event.OnServerEvent:Connect(function(Player)
     local Character = Player.Character
  local newMeshPart = model:Clone()
       local wc = Instance.New("WeldConstraint", newMeshPart)
       newMeshPart.Parent = Character:FindFirstChild("Torso")
       wc.Part0 = Character:FindFirstChild("Torso")
wc.Part1 = newMeshPart.PrimaryPart
newMeshPart.PrimaryPart.CFrame = Character:FindFirstChild("Torso").CFrame
end)

My Bad