im making npcs system but the thing is that these npcs are created in the client and not in the server which means i cant make the humanoid of that npc hold a tool because client npcs cant hold any tools
so the workaround is to create a mesh and add a RigidConstraint and an attachment in the mesh and make the attachment1 of the RigidConstraint to be the mesh’s attachment and attachment0 would be the npc right arm grip attachment
but also some of my tools had an offset for how the tool is held. basically Tool.Grip and it seems to be that i cant set the attachment cframe as the tool.grip (which in theory would make the offset happen) because for some reason the offset isnt the same as when equipping a tool
so if you can please help me on how to make a system where you offset a mesh’s attachment similarly to a tool.grip because ive been stuck for hours on this and theres nothing in the internet that acutally works…
heres the code:
(btw dont mind that this code isnt neatly written i usually brainstorm at the start and then fix the code later on)
local function CreateNpcTool(Npc:Model, Arm:string, Tool:Tool): ()
local Weld = Instance.new("RigidConstraint")
local Attachment = Instance.new("Attachment")
local Handle:BasePart = Tool:FindFirstChild("Handle")
Handle.CFrame = CFrame.new()
local ToolGrip = Tool.Grip
Attachment.Parent = Handle
Weld.Parent = Handle
for i,v in Tool:GetDescendants() do
if v ~= Handle and v:IsA("BasePart") then
v.Parent = Handle
v.Anchored = false
v.CanCollide = false
local WC = Instance.new("WeldConstraint")
WC.Parent = v
WC.Part0 = Handle
WC.Part1 = v
elseif v ~= Handle then
v.Parent = Handle
end
end
Handle.Parent = Npc
Handle.Anchored = false
Handle.CanCollide = false
if Tool:HasTag("Recolor") then
Tool.BrickColor = BrickColor.random()
end
for i,v in Tool:GetDescendants() do
if v:HasTag("Recolor") then
v.BrickColor = BrickColor.random()
end
end
Tool.Parent = Npc
local Arm = Npc[Arm or "Right Arm"]
local ArmAttachment = Arm.RightGripAttachment or Arm.LeftGripAttachment
Arm:SetAttribute("Occuiped", true)
Weld.Attachment1 = Attachment
Weld.Attachment0 = ArmAttachment
Weld.Attachment1.CFrame = ToolGrip -- this dosent work even though it should..
Arm.Tool.Value = Tool
return Handle
end