-- Load config
config = script.Config

ahd = config.Auto_Head_Decap.Value
gore = config.Gore.Value
bod = config.Blood_On_Death.Value


Character = script.Parent
Humanoid = Character.Humanoid
Torso = Character.Torso

function OnDeath()
	Humanoid.Parent = nil
	if Torso then
		Torso.Parent = game.Workspace
		local Head = Character:FindFirstChild("Head")
		if Head then
			Head.Parent = game.Workspace
			local Neck = Instance.new("Weld")
			Neck.Name = "Neck"
			Neck.Part0 = Torso
			Neck.Part1 = Head
			Neck.C0 = CFrame.new(0, 1.5, 0)
			Neck.C1 = CFrame.new()
			Neck.Parent = Torso
			
			script.HDecap:Clone().Parent = Head
			
			if ahd then
				Head:BreakJoints()
				
			if bod then
				blood = game.Lighting.Blood:Clone()
				blood.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				blood.Parent = game.Workspace
				
				blood = game.Lighting.Blood:Clone()
				blood.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				blood.Parent = game.Workspace
				
				blood = game.Lighting.Blood:Clone()
				blood.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				blood.Parent = game.Workspace
			end
			
			if gore then
				brain = game.Lighting["Brain Gib"]:Clone()
				brain.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				brain.Parent = game.Workspace
				
				flesh = game.Lighting["Flesh Gib"]:Clone()
				flesh.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				flesh.Parent = game.Workspace
				
				flesh = game.Lighting["Flesh Gib"]:Clone()
				flesh.CFrame = CFrame.new(Vector3.new(Head.Position.X+math.random(-5,5),Head.Position.Y+math.random(-5,5),Head.Position.Z+math.random(-5,5)))
				flesh.Parent = game.Workspace
			end
			end
		end
		local Limb = Character:FindFirstChild("Right Arm")
		if Limb then
			Limb.Parent = game.Workspace
			script.Decap:Clone().Parent = Limb
			Limb.CFrame = Torso.CFrame * CFrame.new(1.5, 0, 0)
			local Joint = Instance.new("Glue")
			Joint.Name = "RightShoulder"
			Joint.Part0 = Torso
			Joint.Part1 = Limb
			Joint.C0 = CFrame.new(1.5, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			Joint.C1 = CFrame.new(-0, 0.5, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			Joint.Parent = Torso

			local B = Instance.new("Part")
			B.TopSurface = 0
			B.BottomSurface = 0
			B.formFactor = "Symmetric"
			B.Size = Vector3.new(1, 1, 1)
			B.Transparency = 1
			B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
			B.Parent = Character
			local W = Instance.new("Weld")
			W.Part0 = Limb
			W.Part1 = B
			W.C0 = CFrame.new(0, -0.5, 0)
			W.Parent = Limb

		end
		local Limb = Character:FindFirstChild("Left Arm")
		if Limb then
			Limb.Parent = game.Workspace
			script.Decap:Clone().Parent = Limb
			Limb.CFrame = Torso.CFrame * CFrame.new(-1.5, 0, 0)
			local Joint = Instance.new("Glue")
			Joint.Name = "LeftShoulder"
			Joint.Part0 = Torso
			Joint.Part1 = Limb
			Joint.C0 = CFrame.new(-1.5, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			Joint.C1 = CFrame.new(0, 0.5, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			Joint.Parent = Torso

			local B = Instance.new("Part")
			B.TopSurface = 0
			B.BottomSurface = 0
			B.formFactor = "Symmetric"
			B.Size = Vector3.new(1, 1, 1)
			B.Transparency = 1
			B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
			B.Parent = Character
			local W = Instance.new("Weld")
			W.Part0 = Limb
			W.Part1 = B
			W.C0 = CFrame.new(0, -0.5, 0)
			W.Parent = Limb

		end
		local Limb = Character:FindFirstChild("Right Leg")
		if Limb then
			Limb.Parent = game.Workspace
			script.Decap:Clone().Parent = Limb
			Limb.CFrame = Torso.CFrame * CFrame.new(0.5, -2, 0)
			local Joint = Instance.new("Glue")
			Joint.Name = "RightHip"
			Joint.Part0 = Torso
			Joint.Part1 = Limb
			Joint.C0 = CFrame.new(0.5, -1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			Joint.C1 = CFrame.new(0, 1, 0, 0, 0, 1, 0, 1, 0, -1, -0, -0)
			Joint.Parent = Torso

			local B = Instance.new("Part")
			B.TopSurface = 0
			B.BottomSurface = 0
			B.formFactor = "Symmetric"
			B.Size = Vector3.new(1, 1, 1)
			B.Transparency = 1
			B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
			B.Parent = Character
			local W = Instance.new("Weld")
			W.Part0 = Limb
			W.Part1 = B
			W.C0 = CFrame.new(0, -0.5, 0)
			W.Parent = Limb

		end
		local Limb = Character:FindFirstChild("Left Leg")
		if Limb then
			Limb.Parent = game.Workspace
			script.Decap:Clone().Parent = Limb
			Limb.CFrame = Torso.CFrame * CFrame.new(-0.5, -2, 0)
			local Joint = Instance.new("Glue")
			Joint.Name = "LeftHip"
			Joint.Part0 = Torso
			Joint.Part1 = Limb
			Joint.C0 = CFrame.new(-0.5, -1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			Joint.C1 = CFrame.new(-0, 1, 0, -0, -0, -1, 0, 1, 0, 1, 0, 0)
			Joint.Parent = Torso

			local B = Instance.new("Part")
			B.TopSurface = 0
			B.BottomSurface = 0
			B.formFactor = "Symmetric"
			B.Size = Vector3.new(1, 1, 1)
			B.Transparency = 1
			B.CFrame = Limb.CFrame * CFrame.new(0, -0.5, 0)
			B.Parent = Character
			local W = Instance.new("Weld")
			W.Part0 = Limb
			W.Part1 = B
			W.C0 = CFrame.new(0, -0.5, 0)
			W.Parent = Limb

		end
		--[
		local Bar = Instance.new("Part")
		Bar.TopSurface = 0
		Bar.BottomSurface = 0
		Bar.formFactor = "Symmetric"
		Bar.Size = Vector3.new(1, 1, 1)
		Bar.Transparency = 1
		Bar.CFrame = Torso.CFrame * CFrame.new(0, 0.5, 0)
		Bar.Parent = game.Workspace
		local Weld = Instance.new("Weld")
		Weld.Part0 = Torso
		Weld.Part1 = Bar
		Weld.C0 = CFrame.new(0, 0.5, 0)
		Weld.Parent = Torso
		--]]
	end
end

Humanoid.Died:connect(OnDeath)