GetModelPhysBoneCount

This says Line ‘6’ “bones has a nil value”.



function TOOL:LeftClick( tr )

	if (!tr.Entity) then return false end
	if (!tr.Entity:IsValid() ) then return false end
	if (tr.Entity:IsPlayer()) then return false end
	local bones = tr.Entity:GetModelPhysBoneCount()
	return true
end


Are you doing it clientside or serverside?

What exactly are you doing? There’s a better way if you’re trying to use it on ragdolls.

No idea. Single player?

I want to get every possible bone from ragdoll and edit them.



function TOOL:LeftClick( tr )

	if (!tr.Entity) then return false end
	if (!tr.Entity:IsValid() ) then return false end
	if (tr.Entity:IsPlayer()) then return false end
	local bones = tr.Entity:GetModelPhysBoneCount()
       for i=1,bones do 
              ..Edits..
       end
       return true
end


Here’s some code I did while testing, it’s what I see exactly what you need

This script gets all the bones of a ragdoll you are looking at (singleplayer).
[lua]
Bones = {}
if (SERVER) then
for k, v in pairs(player.GetAll()) do

	pos = v:GetShootPos()
	ang = v:GetAimVector()
	tracedata = {}
	tracedata.start = pos
	tracedata.endpos = pos+(ang*8000)
	tracedata.filter = v
	trace = util.TraceLine(tracedata)
	print("traced")

	if trace.HitNonWorld then
		
		target = trace.Entity
		--Add all the bones to a table
		
		for i=0, target:GetPhysicsObjectCount( ) -1 do
			
			local physBone = target:GetPhysicsObjectNum( i )
			if (physBone:IsValid()) then
			
				print(i)
				print(physBone:GetPos())
				print(physBone:GetAngle())
				print(physBone:IsMoveable())
				print("

")

				Bones* = {}
				Bones*.Pos = physBone:GetPos()
				Bones*.Angle = physBone:GetAngle()
				Bones*.Frozen = !physBone:IsMoveable()
			end
		
		end
		

	end

end

print("DONE")

end
[/lua]

and also setting the positions of bones:
[lua]
for k, v in pairs(player.GetAll()) do

	local pos = v:GetShootPos()
	local ang = v:GetAimVector()
	local tracedata = {}
	tracedata.start = pos
	tracedata.endpos = pos+(ang*8000)
	tracedata.filter = v
	trace = util.TraceLine(tracedata)
	print("traced")

	if trace.HitNonWorld then
		
		target = trace.Entity
		
		for i=0, target:GetPhysicsObjectCount( ) -1 do
			
			local physBone = target:GetPhysicsObjectNum( i )
			if ( physBone && physBone:IsValid()) then
			
				print(i)					
				physBone:SetPos(Bones*.Pos)
				physBone:SetAngle(Bones*.Angle)
				
				if ( Bones*.Frozen == true ) then 
					physBone:EnableMotion( false ) 
					v:AddFrozenPhysicsObject( v, physBone )
				end
			end
		
		end
		target:PhysWake( )

	end

end

[/lua]

Partially taken from my body poser stool.

Run the first script serverside/shared, then the second script serverside/shared.

What is the file with that code called and where is it located?