local players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
local torso = char:FindFirstChild("Torso")
if torso then
local M6D = Instance.new("Motor6D")
M6D.Parent = torso
M6D.Name = "ToolGrip"
print("ToolGrip Created")
end
end)
end)
rs.ConnectM6D.OnServerEvent:Connect(function(plr)
local char = plr.Character
local bp = plr.Backpack
local pistol = bp.Pistol
local gun = pistol.Gun
local bodyAttach = gun.BodyAttach
local torso = char:FindFirstChild("Torso")
if torso then
torso.ToolGrip.Part0 = torso
torso.ToolGrip.Part1 = bodyAttach
end
end)
rs.DisconnectM6D.OnServerEvent:Connect(function(plr)
local char = plr.Character
local torso = char:FindFirstChild("Torso")
if torso then
torso.ToolGrip.Part1 = nil
end
end)
Remember that because “Torso” is where the Motor6D instance is parented to this will only work for R6 avatars as for R15 avatars that joint is split into a lower torso and upper torso.
It’s also best to avoid using the parent parameter, more about that here.
I’ve swapped CharacterAdded for CharacterAppearanceLoaded as that fires when the character’s avatar is loaded.
You’re also referencing the tool inside StarterPack, not the tool inside the backpack folder of the player instance (which is where tools are copied to from the StarterPack folder each time the player’s character reloads/spawns etc.).