Trying to duplicate the player model when player dies. help?

So I’m trying to make a cool death script that can duplicate the dead body. I’m going to add more things, but right now this is my only problem. I’ve written this code here:

local character = script.Parent 
local humanoid = character:WaitForChild("Humanoid")
humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Dead then
		local body = character:Clone()
		body.Torso.Position = Vector3.new(character.Torso.Position)
		body.Parent = workspace
	end
end)

But then it throws this error:
LocalScript:6: attempt to index nil with 'Torso'

How can I fix this?

Its because Torso is not a child of Character. Its a child of Humanoid.

Try this:

local character = script.Parent 
local humanoid = character:WaitForChild("Humanoid")
humanoid.StateChanged:Connect(function(oldState, newState)
	if newState == Enum.HumanoidStateType.Dead then
		local body = character:Clone()
		body.Torso.Position = Vector3.new(humanoid.Torso.Position)
		body.Parent = workspace
	end
end)