NPC ragdoll, works for players

This ragdoll script works for players, but how do I make it work for NPC’s. I can’t just drop it into a NPC because it calls for the player. Do I just get rid of the first two lines?


game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Char)
		Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
		Char.Humanoid.Died:Connect(function()
			for _, v in pairs(Char:GetDescendants()) do
				if v:IsA("Motor6D") then
					local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
					Att0.CFrame = v.C0
					Att1.CFrame = v.C1
					Att0.Parent = v.Part0
					Att1.Parent = v.Part1
					local BSC = Instance.new("BallSocketConstraint")
					BSC.Attachment0 = Att0
					BSC.Attachment1 = Att1
					BSC.Parent = v.Part0

					v:Destroy()
				end
			end
			Char.HumanoidRootPart.CanCollide = false
		end)
	end)
end)
2 Likes
local Char = script.Parent

Char:WaitForChild("Humanoid").BreakJointsOnDeath = false
Char.Humanoid.Died:Connect(function()
   for _, v in pairs(Char:GetDescendants()) do
     if v:IsA("Motor6D") then
        local Att0, Att1 = Instance.new("Attachment"), Instance.new("Attachment")
        Att0.CFrame = v.C0
        Att1.CFrame = v.C1
        Att0.Parent = v.Part0
        Att1.Parent = v.Part1
        local BSC = Instance.new("BallSocketConstraint")
        BSC.Attachment0 = Att0
        BSC.Attachment1 = Att1
        BSC.Parent = v.Part0
        v:Destroy()
     end
  end
    Char.HumanoidRootPart.CanCollide = false
end)

Just Define the Character as the Script’s parent instead of the newly added character and move the script into the NPC.

5 Likes