I have been trying to make a throwing knife and it all works well except one part - for some reason all the parts inside my knife model become split up. A knife model itself have wield constraints with all parts and they all wielded to handle. Here is the code I use:
local throwPart = game.ServerStorage.KnivesModels.Default:Clone()
throwPart:SetPrimaryPartCFrame(player.Character.Head.CFrame)
for i, child in pairs(throwPart:GetChildren()) do
local b = bodyforce:Clone()
b.Force = Vector3.new(0, child:GetMass()*workspace.Gravity, 0)
b.Parent = child
child.Velocity = FinalRay.Direction/2
child.CFrame = CFrame.new(player.Character.Head.Position, (child.Velocity +child.Position))
end
I see you’re using :SetPrimaryPartCFrame at the top of your script but not inside of your loop. The loop probably wouldn’t even be necessary if you just set the PrimaryPart of the knife to the handle or something.
This is because you are sending all the parts to one point. To fix this you can either create a mesh knife that’s only one part, or use WeldConstraints and any type of way to move the knife.
Thanks a lot, I needed the loop for many other things (this is just the part of the code). I changed it, here is the solution if anyone ever will need it:
for i, child in pairs(throwPart:GetChildren()) do
local b = bodyforce:Clone()
b.Force = Vector3.new(0, child:GetMass()*workspace.Gravity, 0)
b.Parent = child
child.Velocity = FinalRay.Direction/2
end
throwPart:SetPrimaryPartCFrame(CFrame.new(player.Character.Head.Position,(throwPart.Handle.Velocity + throwPart.Handle.Position)))