I’m trying to weld backpacks & items to a player’s character.
When I tested this, people without the default character meshes for the body parts I’m trying to weld to don’t have the backpacks or items.
I’ve already debugged it, and there was nothing out of the ordinary.
m.EquipExplosive = function(player)
local character = player.Character
print(1)
if character then
print(2)
for i,v in next, character:GetChildren() do
if v.Name == "GameExplosive" then
v:Destroy()
end
end
local data = PlayerData.PlayerData[tostring(player.UserId)]
if data then
print(3)
local einfo = GameData["Explosives"][data.CurrentExplosive]
if einfo then
print(4)
local model = Explosives:FindFirstChild(data.CurrentExplosive)
if model then
print(5)
local rhand = character:FindFirstChild("RightHand")
if rhand then
print(6)
local new = model:Clone()
new.Name = "GameExplosive"
local handle = new:WaitForChild("Handle")
for i,v in next, new:GetChildren() do
if v ~= handle then
local weld = Instance.new("Motor6D",handle)
weld.Part0 = handle
weld.Part1 = v
weld.C0 = CFrame.new().toObjectSpace(handle.CFrame,v.CFrame)
v.Anchored = false
end
end
local mainweld = Instance.new("Motor6D",handle)
mainweld.Part0 = rhand
mainweld.Part1 = handle
handle.Anchored = false
handle.Transparency = 1
local info = ExplosiveInfo:Clone()
info.Parent = new
new.Parent = character
for i,v in next, info:GetChildren() do
if v:IsA("Script") or v:IsA("LocalScript") then
v.Disabled = false
end
end
wait(0.1)
print(new.Parent,mainweld.Part0,mainweld.Part1)
end
end
end
end
end
I’ve created a simple function for you to weld items to a player’s back. To use this function it will require you to have an object, which is a model with a specified PrimaryPart. You may specify an optional offset. I have also provided an example .rbxl file that shows this function in use.
This should allow you to weld “backpacks” to a player’s back which will work with any type of package, including R6. If you need to make things weld to the player’s hand, you can change CharacterTorso to their RightHand or LeftHand, this function is primarily just an example of how to weld it correctly. If you have any questions feel free to ask.
local function AttachToBack(Player, Object, Offset)
if not Offset then Offset = Vector3.new(0, 0, 0) end
Object = Object:Clone()
local Character = Player.Character or Player.CharacterAdded:Wait()
local CharacterTorso = Character:FindFirstChild("Torso") or Character:FindFirstChild("UpperTorso")
Object.Parent = Character
Object:SetPrimaryPartCFrame(CharacterTorso.CFrame * CFrame.new(Offset))
local Weld = Instance.new("WeldConstraint")
Weld.Parent = Object
Weld.Part0 = CharacterTorso
Weld.Part1 = Object.PrimaryPart
end
Here is the .rbxl file; you can find the testing model inside ReplicatedStorage and the primary script which showcases this function in ServerScriptService. SampleBagWelding.rbxl (15.6 KB)
Um this doesn’t include welding and I’m not sure if your mechanics would interfere with this but I would just use an assecory with a body back attachment and clone it into the player to make a backpack
Why did you need to take the code from my .rbxl file which I provided above and give him the same thing with one difference…? Plus the functionality you added was already in the function, you just added unnecessary code, I won’t make this out to be a big deal but that feel’s like a great slap in the face towards me.
P.S. If you bothered to read my code, you’d realize you don’t need the “if statement” to check if Player.Character is a thing.
The reason his worked rather than yours, and the solution to my issue was simply the Player.CharacterAppearanceLoaded event, which was preventing me to weld something to the character’s hand or upper torso the moment the character is added.
This is the solution that works for Embers case. @CleverSource solution does not work on players using a different body other than the default Roblox char. His solution also does not weld the backpack together as ember stated he needed. I was also told that my post was deleted and clever’s post was made solution without Embers influence, even though mine was marked as the solution earlier.
local function AttachToBack(player, object)
object = object:Clone()
local char = player.Character
object.Parent = char
object:SetPrimaryPartCFrame(char.UpperTorso.CFrame)
for _, v in pairs(object:GetChildren()) do
if v:IsA("BasePart") and v ~= object.PrimaryPart then
local weldPart = Instance.new("WeldConstraint")
weldPart.Parent = object.PrimaryPart
weldPart.Part0 = object.PrimaryPart
weldPart.Part1 = v
end
end
local weld = Instance.new("Motor6D")
weld.C0 = CFrame.new(char.HumanoidRootPart.CFrame.lookVector * -.75)
weld.Parent = char.UpperTorso
weld.Part0 = char.UpperTorso
weld.Part1 = object.PrimaryPart
end
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
Players.PlayerAdded:Connect(function(player)
player.CharacterAppearanceLoaded:Connect(function(character)
AttachToBack(player, ReplicatedStorage.TestModel)
end)
end)