--Connections

playerService.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		
		local rootPart = character:WaitForChild("HumanoidRootPart")
		
		local humanoid = character:WaitForChild("Humanoid")
		local oldHealth = humanoid.Health
		
		local particlesClone = bloodParticles:Clone()
		particlesClone.Parent = rootPart
		
		humanoid.HealthChanged:Connect(function(health)
			if health < oldHealth then
				
				oldHealth = health
				
				spawn(function()
					for i = 1, blood_part_per_hit do
						
						local randomPosition = math.random(-20, 20) / 10
						
						local raycastOrigin = rootPart.Position + Vector3.new(randomPosition, 0, randomPosition)
						local raycastDirection = Vector3.new(0, -8, 0)
						
						local raycastResult = raycast(character, raycastOrigin, raycastDirection)
						
						if raycastResult then
							particlesClone:Emit(2)
							
							delay(0.5, function()
								local newBlood = createBlood(raycastResult.Position)
								expandBlood(newBlood)
								
								delay(blood_destroy_delay, function()
									deleteBlood(newBlood)
								end)
							end)
						end
						
						wait(math.random(0.5, 2) / 10)
					end
				end)
			else
				oldHealth = health
			end
		end)
	end)
end)
