Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Connecting Meshes to Character (Suggestions?)

Hi there,

I was wondering if it was possible to connect (weld?) a filemesh to your character, and if so, how you would go about doing this. Just in case the question is unclear, I will give an example.

So let's say I have a 3D model of a backpack I made in another program. I would like to attach that backpack to a player's character. However, I'm not sure how I should do this (should I use a weld? Make the backpack a tool?). I already have a filemesh uploaded in Roblox Studio, so please do not explain how to upload a filemesh.

Any suggestions would be much appreciated! If you need any further explanation, feel free to comment.

1 answer

✓ Accepted answer

I believe that the best option would be to have a block the size of the characters Torso that is welded to the backpack, and gets welded to the players Torso when they spawn or however you choose to do it.

Here is a script I made about a year ago to attach blocks to player's characters:

function Torso(char)
	local g = game.ServerStorage.Backpack:Clone();
	g.Parent = char;
	local C = g:GetChildren();
	for i=1, #C do
		if C[i]:IsA("BasePart")then
			local W = Instance.new("Weld");
			W.Part0 = g.Middle;
			W.Part1 = C[i];
			local CJ = CFrame.new(g.Middle.Position);
			local C0 = g.Middle.CFrame:inverse()*CJ;
			local C1 = C[i].CFrame:inverse()*CJ;
			W.C0 = C0;
			W.C1 = C1;
			W.Parent = g.Middle;
		end;
			local Y = Instance.new("Weld");
			Y.Part0 = char:FindFirstChild("Torso");
			Y.Part1 = g.Middle;
			Y.C0 = CFrame.new(0, 0, 0);
			Y.Parent = Y.Part0;
	end;

	local h = g:GetChildren();
	for i = 1, # h do
		if h[i]:IsA("BasePart") then
			h[i].Anchored = false;
			h[i].CanCollide = false;
		end;
	end;
end;

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		wait(2);
		Torso(char);
	end);
end);

This code will move the model based on the piece called Middle (Note: This piece is the one that is the size of the Torso). I hope this helped. If it did please accept this as the answer so that people know it has been solved.

5 comments

0

Thank you for your answer! I am getting an error on line 34 of your script where there was an expected ")" to close the statement. I also wasn't sure if I should place this script in ServerScriptService, StarterPack, or something else.

0

The error to his script is line 37/38, both must beend)

0

Due to your script being old, you may already know this, but you can say if part:IsA("BasePart") then.. This references all physicals parts such as Parts, Unions, Wedges, etc...

0

Okay so I have a Model with both the Filemesh and a weld part named "Middle" in it. This Model is in ServerStorage. I went to test it out and the model was not attached to my character. Does the script have to be local? Is the way I set it up incorrect?

0

If the model is in server storage you can't use a localscirpt. You would need to use a regular script. Hence why the game.Players.PlayerAdded at the bottom. alphawolves, I know about :IsA("BasePart") and I was really tired when I typed this script out so I blanked on a lot of things (i.e., the closing ')' on lines 37 and 38)

This discussion is preserved as it was. New answers, comments, and votes are closed.